Add relational models for plants and related fields (excludes habitat and zone)

This commit is contained in:
Dana Lambert 2021-10-15 14:33:13 +13:00
parent 6dfa65ee77
commit e068ed047b
2 changed files with 146 additions and 4 deletions

View file

@ -1,6 +1,8 @@
# Generated by Django 3.2.8 on 2021-10-06 18:32
# Generated by Django 3.2.8 on 2021-10-15 01:23
import django.contrib.gis.db.models.fields
from django.db import migrations, models
import django.db.models.deletion
class Migration(migrations.Migration):
@ -11,11 +13,77 @@ class Migration(migrations.Migration):
]
operations = [
migrations.CreateModel(
name='EcologicalRegion',
fields=[
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('name', models.CharField(max_length=50, unique=True)),
],
),
migrations.CreateModel(
name='SoilOrder',
fields=[
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('code', models.CharField(max_length=1, unique=True)),
('name', models.CharField(max_length=50, unique=True)),
],
),
migrations.CreateModel(
name='SoilVariant',
fields=[
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('name', models.CharField(max_length=10, unique=True)),
],
),
migrations.CreateModel(
name='ToleranceLevel',
fields=[
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('level', models.CharField(max_length=1)),
],
),
migrations.CreateModel(
name='SoilLayer',
fields=[
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('nzsc_class', models.CharField(max_length=4)),
('nzsc_group', models.CharField(max_length=2)),
('shape_leng', models.FloatField()),
('geom', django.contrib.gis.db.models.fields.PolygonField(srid=2193)),
('nzsc_order', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='api.soilorder')),
],
),
migrations.CreateModel(
name='Plant',
fields=[
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('name', models.TextField()),
('name', models.CharField(max_length=50, unique=True)),
('commonname', models.CharField(blank=True, max_length=50, null=True)),
('maxheight', models.FloatField()),
('spacing', models.FloatField()),
('synonym', models.CharField(blank=True, max_length=200, null=True)),
('purpose', models.TextField(blank=True, null=True)),
('stage', models.PositiveIntegerField()),
('growth_form', models.CharField(blank=True, max_length=50, null=True)),
('drought_tolerance', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='drought_tolerance', to='api.tolerancelevel')),
('ecological_regions', models.ManyToManyField(to='api.EcologicalRegion')),
('frost_tolerance', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='frost_tolerance', to='api.tolerancelevel')),
('salinity_tolerance', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='salinity_tolerance', to='api.tolerancelevel')),
('soil_order', models.ManyToManyField(to='api.SoilOrder')),
('soil_variants', models.ManyToManyField(to='api.SoilVariant')),
('water_tolerance', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='water_tolerance', to='api.tolerancelevel')),
],
),
migrations.CreateModel(
name='EcologicalDistrictLayer',
fields=[
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('ecological', models.CharField(max_length=5)),
('ecologic_1', models.CharField(max_length=50)),
('shape_leng', models.FloatField()),
('shape_area', models.FloatField()),
('geom', django.contrib.gis.db.models.fields.PolygonField(srid=2193)),
('ecologic_2', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='api.ecologicalregion')),
],
),
]

View file

@ -1,4 +1,78 @@
from django.db import models
from django.contrib.gis.db import models
class SoilOrder(models.Model):
code = models.CharField(unique=True, max_length=1)
name = models.CharField(unique=True, max_length=50)
def __str__(self):
return f"{self.name} ({self.code})"
class SoilVariant(models.Model):
name = models.CharField(unique=True, max_length=10)
def __str__(self):
return self.name
class SoilLayer(models.Model):
nzsc_class = models.CharField(max_length=4)
nzsc_group = models.CharField(max_length=2)
nzsc_order = models.ForeignKey(SoilOrder, on_delete=models.CASCADE)
shape_leng = models.FloatField()
geom = models.PolygonField(srid=2193)
def __str__(self):
return self.nzsc_class
class EcologicalRegion(models.Model):
name = models.CharField(unique=True, max_length=50)
def __str__(self):
return self.name
class EcologicalDistrictLayer(models.Model):
ecological = models.CharField(max_length=5)
ecologic_1 = models.CharField(max_length=50)
ecologic_2 = models.ForeignKey(EcologicalRegion, on_delete=models.CASCADE)
shape_leng = models.FloatField()
shape_area = models.FloatField()
geom = models.PolygonField(srid=2193)
def __str__(self):
return f"{self.ecologic_1} ({self.ecologic_2})"
class ToleranceLevel(models.Model):
level = models.CharField(max_length=1)
def __str__(self):
return self.level
class Plant(models.Model):
name = models.TextField()
name = models.CharField(unique=True, max_length=50)
commonname = models.CharField(null=True, blank=True, max_length=50)
maxheight = models.FloatField()
spacing = models.FloatField()
synonym = models.CharField(null=True, blank=True, max_length=200)
water_tolerance = models.ForeignKey(
ToleranceLevel, related_name='water_tolerance', on_delete=models.CASCADE)
drought_tolerance = models.ForeignKey(
ToleranceLevel, related_name='drought_tolerance', on_delete=models.CASCADE)
frost_tolerance = models.ForeignKey(
ToleranceLevel, related_name='frost_tolerance', on_delete=models.CASCADE)
salinity_tolerance = models.ForeignKey(
ToleranceLevel, related_name='salinity_tolerance', on_delete=models.CASCADE)
purpose = models.TextField(null=True, blank=True)
stage = models.PositiveIntegerField()
growth_form = models.CharField(null=True, blank=True, max_length=50)
ecological_regions = models.ManyToManyField(EcologicalRegion)
soil_order = models.ManyToManyField(SoilOrder)
soil_variants = models.ManyToManyField(SoilVariant)
def __str__(self):
return self.name