fix: use related_name='pruning_logs' and PositiveIntegerField for max_height_cm
This commit is contained in:
parent
2c61b03519
commit
4495a07407
3 changed files with 41 additions and 2 deletions
|
|
@ -0,0 +1,24 @@
|
||||||
|
# Generated by Django 5.1.15 on 2026-05-27 17:58
|
||||||
|
|
||||||
|
import django.db.models.deletion
|
||||||
|
from django.db import migrations, models
|
||||||
|
|
||||||
|
|
||||||
|
class Migration(migrations.Migration):
|
||||||
|
|
||||||
|
dependencies = [
|
||||||
|
('plants', '0001_initial'),
|
||||||
|
]
|
||||||
|
|
||||||
|
operations = [
|
||||||
|
migrations.AlterField(
|
||||||
|
model_name='pruninglog',
|
||||||
|
name='plant',
|
||||||
|
field=models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='pruning_logs', to='plants.plant'),
|
||||||
|
),
|
||||||
|
migrations.AlterField(
|
||||||
|
model_name='species',
|
||||||
|
name='max_height_cm',
|
||||||
|
field=models.PositiveIntegerField(blank=True, null=True),
|
||||||
|
),
|
||||||
|
]
|
||||||
|
|
@ -8,7 +8,7 @@ class Species(models.Model):
|
||||||
watering = models.CharField(max_length=100, blank=True)
|
watering = models.CharField(max_length=100, blank=True)
|
||||||
sunlight = models.CharField(max_length=200, blank=True)
|
sunlight = models.CharField(max_length=200, blank=True)
|
||||||
shadow_tolerance = models.CharField(max_length=100, blank=True)
|
shadow_tolerance = models.CharField(max_length=100, blank=True)
|
||||||
max_height_cm = models.IntegerField(null=True, blank=True)
|
max_height_cm = models.PositiveIntegerField(null=True, blank=True)
|
||||||
growth_rate = models.CharField(max_length=100, blank=True)
|
growth_rate = models.CharField(max_length=100, blank=True)
|
||||||
growth_season = models.CharField(max_length=100, blank=True)
|
growth_season = models.CharField(max_length=100, blank=True)
|
||||||
pruning_months = models.JSONField(default=list)
|
pruning_months = models.JSONField(default=list)
|
||||||
|
|
@ -45,7 +45,7 @@ class Plant(models.Model):
|
||||||
|
|
||||||
class PruningLog(models.Model):
|
class PruningLog(models.Model):
|
||||||
plant = models.ForeignKey(
|
plant = models.ForeignKey(
|
||||||
Plant, on_delete=models.CASCADE, related_name='pruninglogs',
|
Plant, on_delete=models.CASCADE, related_name='pruning_logs',
|
||||||
)
|
)
|
||||||
pruned_on = models.DateField()
|
pruned_on = models.DateField()
|
||||||
notes = models.TextField(blank=True)
|
notes = models.TextField(blank=True)
|
||||||
|
|
|
||||||
|
|
@ -33,3 +33,18 @@ def test_pruning_log_str():
|
||||||
def test_plant_pruning_months_default():
|
def test_plant_pruning_months_default():
|
||||||
p = Plant.objects.create(name='Fern', location='Office')
|
p = Plant.objects.create(name='Fern', location='Office')
|
||||||
assert p.pruning_months == []
|
assert p.pruning_months == []
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.mark.django_db
|
||||||
|
def test_species_pruning_months_default():
|
||||||
|
s = Species.objects.create(common_name='Oak')
|
||||||
|
assert s.pruning_months == []
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.mark.django_db
|
||||||
|
def test_delete_species_nulls_plant_species():
|
||||||
|
s = Species.objects.create(common_name='Rose')
|
||||||
|
p = Plant.objects.create(name='Garden rose', location='Garden', species=s)
|
||||||
|
s.delete()
|
||||||
|
p.refresh_from_db()
|
||||||
|
assert p.species is None
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue