Add Habitat, Zone, HabitatImage and ZoneImageSegment models
This commit is contained in:
parent
677ffb2c32
commit
745b0b3007
3 changed files with 104 additions and 8 deletions
|
@ -1,10 +1,14 @@
|
|||
from django.contrib import admin
|
||||
from right_tree.api.models import Plant, SoilOrder, SoilLayer, SoilVariant, EcologicalRegion, EcologicalDistrictLayer, ToleranceLevel
|
||||
import right_tree.api.models as models
|
||||
|
||||
admin.site.register(Plant)
|
||||
admin.site.register(SoilOrder)
|
||||
admin.site.register(SoilLayer)
|
||||
admin.site.register(SoilVariant)
|
||||
admin.site.register(EcologicalRegion)
|
||||
admin.site.register(EcologicalDistrictLayer)
|
||||
admin.site.register(ToleranceLevel)
|
||||
admin.site.register(models.Plant)
|
||||
admin.site.register(models.SoilOrder)
|
||||
admin.site.register(models.SoilLayer)
|
||||
admin.site.register(models.SoilVariant)
|
||||
admin.site.register(models.EcologicalRegion)
|
||||
admin.site.register(models.EcologicalDistrictLayer)
|
||||
admin.site.register(models.ToleranceLevel)
|
||||
admin.site.register(models.HabitatImage)
|
||||
admin.site.register(models.Habitat)
|
||||
admin.site.register(models.Zone)
|
||||
admin.site.register(models.ZoneImageSegment)
|
||||
|
|
|
@ -0,0 +1,50 @@
|
|||
# Generated by Django 3.2.8 on 2021-11-03 21:38
|
||||
|
||||
from django.db import migrations, models
|
||||
import django.db.models.deletion
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('api', '0001_initial'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.CreateModel(
|
||||
name='Habitat',
|
||||
fields=[
|
||||
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
|
||||
('name', models.CharField(max_length=50)),
|
||||
],
|
||||
),
|
||||
migrations.CreateModel(
|
||||
name='HabitatImage',
|
||||
fields=[
|
||||
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
|
||||
('name', models.CharField(max_length=50)),
|
||||
('image_filename', models.CharField(default='-', max_length=50)),
|
||||
('habitat', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='habitat', to='api.habitat')),
|
||||
],
|
||||
),
|
||||
migrations.CreateModel(
|
||||
name='Zone',
|
||||
fields=[
|
||||
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
|
||||
('name', models.CharField(max_length=50)),
|
||||
('variant', models.CharField(blank=True, max_length=50, null=True)),
|
||||
('refined_variant', models.CharField(blank=True, max_length=100, null=True)),
|
||||
('redirect_habitat', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.CASCADE, related_name='redirect_habitat', to='api.habitat')),
|
||||
],
|
||||
),
|
||||
migrations.CreateModel(
|
||||
name='ZoneImageSegment',
|
||||
fields=[
|
||||
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
|
||||
('segment_order', models.PositiveIntegerField(default=0)),
|
||||
('segment_percentage_width', models.PositiveIntegerField(default=0)),
|
||||
('habitat_image', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='habitat_image', to='api.habitatimage')),
|
||||
('zone', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='zone', to='api.zone')),
|
||||
],
|
||||
),
|
||||
]
|
|
@ -76,3 +76,45 @@ class Plant(models.Model):
|
|||
|
||||
def __str__(self):
|
||||
return self.name
|
||||
|
||||
|
||||
class Habitat(models.Model):
|
||||
name = models.CharField(max_length=50)
|
||||
|
||||
def __str__(self):
|
||||
return self.name
|
||||
|
||||
|
||||
class HabitatImage(models.Model):
|
||||
habitat = models.ForeignKey(
|
||||
Habitat, related_name='habitat', on_delete=models.CASCADE)
|
||||
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(
|
||||
Habitat, blank=True, null=True, on_delete=models.CASCADE, related_name='redirect_habitat')
|
||||
|
||||
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}"
|
||||
|
||||
|
||||
class ZoneImageSegment(models.Model):
|
||||
zone = models.ForeignKey(
|
||||
Zone, on_delete=models.CASCADE, related_name='zone')
|
||||
habitat_image = models.ForeignKey(
|
||||
HabitatImage, on_delete=models.CASCADE, related_name='habitat_image')
|
||||
segment_order = models.PositiveIntegerField(default=0)
|
||||
segment_percentage_width = models.PositiveIntegerField(default=0)
|
||||
|
||||
def __str__(self):
|
||||
return f"{self.habitat_image.name}, {self.zone.name}"
|
||||
|
|
Loading…
Reference in a new issue