2021-10-15 14:33:13 +13:00
|
|
|
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
|
|
|
|
|
2021-11-05 14:22:07 +13:00
|
|
|
|
2021-11-04 11:18:04 +13:00
|
|
|
class Habitat(models.Model):
|
|
|
|
name = models.CharField(max_length=50)
|
|
|
|
|
|
|
|
def __str__(self):
|
|
|
|
return self.name
|
|
|
|
|
|
|
|
|
|
|
|
class HabitatImage(models.Model):
|
|
|
|
habitat = models.ForeignKey(
|
2021-11-05 11:13:59 +13:00
|
|
|
Habitat, related_name='images', on_delete=models.CASCADE)
|
2021-11-04 11:18:04 +13:00
|
|
|
name = models.CharField(max_length=50)
|
|
|
|
image_filename = models.CharField(max_length=50, default='-')
|
|
|
|
|
|
|
|
def __str__(self):
|
|
|
|
return self.name
|
|
|
|
|
|
|
|
|
|
|
|
class Zone(models.Model):
|
|
|
|
name = models.CharField(max_length=50)
|
|
|
|
variant = models.CharField(null=True, blank=True, max_length=50)
|
|
|
|
refined_variant = models.CharField(null=True, blank=True, max_length=100)
|
|
|
|
redirect_habitat = models.ForeignKey(
|
2021-11-11 13:26:04 +13:00
|
|
|
Habitat, blank=True, null=True, on_delete=models.CASCADE, related_name='zone_redirects')
|
2021-11-10 13:11:13 +13:00
|
|
|
ignore_soil_order_filter = models.BooleanField(default=False)
|
|
|
|
ignore_location_filter = models.BooleanField(default=False)
|
2021-11-04 11:18:04 +13:00
|
|
|
|
|
|
|
def __str__(self):
|
|
|
|
refined_variant_str = f", {self.refined_variant}" if self.refined_variant is not None else ""
|
|
|
|
variant_str = f"({self.variant}{refined_variant_str})" if self.variant is not None else ""
|
|
|
|
return f"{self.name} {variant_str}"
|
|
|
|
|
2021-11-05 16:18:47 +13:00
|
|
|
class Meta:
|
|
|
|
ordering = ['name', 'variant', 'refined_variant', 'id']
|
|
|
|
|
2021-11-04 11:18:04 +13:00
|
|
|
|
|
|
|
class ZoneImageSegment(models.Model):
|
|
|
|
zone = models.ForeignKey(
|
2021-11-05 14:22:07 +13:00
|
|
|
Zone, on_delete=models.CASCADE, related_name='image_segments')
|
2021-11-04 11:18:04 +13:00
|
|
|
habitat_image = models.ForeignKey(
|
2021-11-05 14:22:07 +13:00
|
|
|
HabitatImage, on_delete=models.CASCADE, related_name='image_segments')
|
2021-11-04 11:18:04 +13:00
|
|
|
segment_order = models.PositiveIntegerField(default=0)
|
2021-11-10 17:34:16 +13:00
|
|
|
segment_percentage_width = models.FloatField(default=0)
|
2021-11-04 11:18:04 +13:00
|
|
|
|
|
|
|
def __str__(self):
|
2021-11-10 17:34:16 +13:00
|
|
|
return f"{self.habitat_image.name}, {self.zone}"
|
2021-11-04 14:08:31 +13:00
|
|
|
|
2021-11-05 14:22:07 +13:00
|
|
|
class Meta:
|
|
|
|
ordering = ['segment_order', 'id']
|
|
|
|
|
2021-11-04 14:08:31 +13:00
|
|
|
|
|
|
|
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)
|
|
|
|
|
2021-11-10 10:33:34 +13:00
|
|
|
@property
|
|
|
|
def forest_position(self):
|
|
|
|
return self.zones.all().filter(name="BUSH PROFILE POSITION", variant__in={"Core", "Border", "Skin"}).values('variant')
|
|
|
|
|
2021-11-08 15:51:05 +13:00
|
|
|
@property
|
|
|
|
def display_name(self):
|
|
|
|
common_name_str = f' / {str(self.commonname)}' if self.commonname is not None else ''
|
|
|
|
synonym_str = f' / {str(self.synonym)}' if self.synonym is not None else ''
|
|
|
|
return f"{self.name}{common_name_str}{synonym_str}"
|
|
|
|
|
|
|
|
@property
|
|
|
|
def display_growth_form(self):
|
|
|
|
growth_form_str = f'{str(self.growth_form)} / ' if self.growth_form is not None else ''
|
2021-11-10 10:33:34 +13:00
|
|
|
forest_position_values_str = ', '.join([position['variant'][0] for position in self.forest_position])
|
|
|
|
forest_position_str = f' / {forest_position_values_str}' if self.forest_position is not None else ''
|
|
|
|
return f"{growth_form_str}{self.maxheight} / {self.spacing}{forest_position_str}"
|
2021-11-08 15:51:05 +13:00
|
|
|
|
|
|
|
@property
|
|
|
|
def moisture_preferences(self):
|
|
|
|
return ', '.join([variant.name for variant in self.soil_variants.all()])
|
|
|
|
|
|
|
|
@property
|
|
|
|
def plant_tolerances(self):
|
|
|
|
return f"{self.water_tolerance.level} / {self.drought_tolerance.level} / {self.frost_tolerance.level} / {self.salinity_tolerance.level}"
|
|
|
|
|
|
|
|
@property
|
|
|
|
def ecosystem_services(self):
|
|
|
|
return f"{str(self.purpose) or ''}"
|
|
|
|
|
|
|
|
@property
|
|
|
|
def carbon_sequestration(self):
|
|
|
|
return ""
|
|
|
|
|
2021-11-04 14:08:31 +13:00
|
|
|
def __str__(self):
|
2021-11-05 14:22:07 +13:00
|
|
|
return self.name
|
2021-11-17 10:32:54 +13:00
|
|
|
|
|
|
|
class Meta:
|
|
|
|
ordering = ['stage', 'name', 'commonname', 'synonym']
|