From d48f202634c58e59ed33af84b7257bc5d40244c0 Mon Sep 17 00:00:00 2001 From: Dana Lambert Date: Thu, 4 Nov 2021 14:08:31 +1300 Subject: [PATCH] Add zones to plant model --- .../api/migrations/0003_plant_zones.py | 18 +++++++ backend/right_tree/api/models.py | 52 +++++++++---------- 2 files changed, 44 insertions(+), 26 deletions(-) create mode 100644 backend/right_tree/api/migrations/0003_plant_zones.py diff --git a/backend/right_tree/api/migrations/0003_plant_zones.py b/backend/right_tree/api/migrations/0003_plant_zones.py new file mode 100644 index 0000000..76a88ab --- /dev/null +++ b/backend/right_tree/api/migrations/0003_plant_zones.py @@ -0,0 +1,18 @@ +# Generated by Django 3.2.8 on 2021-11-04 00:03 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('api', '0002_habitat_habitatimage_zone_zoneimagesegment'), + ] + + operations = [ + migrations.AddField( + model_name='plant', + name='zones', + field=models.ManyToManyField(to='api.Zone'), + ), + ] diff --git a/backend/right_tree/api/models.py b/backend/right_tree/api/models.py index 9dcc5d4..ea1bdda 100644 --- a/backend/right_tree/api/models.py +++ b/backend/right_tree/api/models.py @@ -52,32 +52,6 @@ class ToleranceLevel(models.Model): def __str__(self): return self.level - -class Plant(models.Model): - name = models.CharField(unique=True, max_length=50) - commonname = models.CharField(null=True, blank=True, max_length=200) - 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 - - class Habitat(models.Model): name = models.CharField(max_length=50) @@ -118,3 +92,29 @@ class ZoneImageSegment(models.Model): def __str__(self): return f"{self.habitat_image.name}, {self.zone.name}" + + +class Plant(models.Model): + name = models.CharField(unique=True, max_length=50) + commonname = models.CharField(null=True, blank=True, max_length=200) + 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) + zones = models.ManyToManyField(Zone) + + def __str__(self): + return self.name \ No newline at end of file