feat: add PlantCardPhoto model
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
parent
e123e1d7cc
commit
4132406f15
3 changed files with 63 additions and 0 deletions
26
plants/migrations/0007_plantcardphoto.py
Normal file
26
plants/migrations/0007_plantcardphoto.py
Normal file
|
|
@ -0,0 +1,26 @@
|
|||
# Generated by Django 5.2.1 on 2026-05-28 19:37
|
||||
|
||||
import django.db.models.deletion
|
||||
from django.db import migrations, models
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('plants', '0006_species_vpc_raw'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.CreateModel(
|
||||
name='PlantCardPhoto',
|
||||
fields=[
|
||||
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
|
||||
('image', models.ImageField(upload_to='plants/cards/')),
|
||||
('uploaded_at', models.DateTimeField(auto_now_add=True)),
|
||||
('plant', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='card_photos', to='plants.plant')),
|
||||
],
|
||||
options={
|
||||
'ordering': ['uploaded_at'],
|
||||
},
|
||||
),
|
||||
]
|
||||
|
|
@ -82,6 +82,15 @@ class PlantPhoto(models.Model):
|
|||
ordering = ['uploaded_at']
|
||||
|
||||
|
||||
class PlantCardPhoto(models.Model):
|
||||
plant = models.ForeignKey(Plant, on_delete=models.CASCADE, related_name='card_photos')
|
||||
image = models.ImageField(upload_to='plants/cards/')
|
||||
uploaded_at = models.DateTimeField(auto_now_add=True)
|
||||
|
||||
class Meta:
|
||||
ordering = ['uploaded_at']
|
||||
|
||||
|
||||
class PruningLog(models.Model):
|
||||
plant = models.ForeignKey(
|
||||
Plant, on_delete=models.CASCADE, related_name='pruning_logs',
|
||||
|
|
|
|||
|
|
@ -53,3 +53,31 @@ def test_delete_species_nulls_plant_species():
|
|||
s.delete()
|
||||
p.refresh_from_db()
|
||||
assert p.species is None
|
||||
|
||||
|
||||
@pytest.mark.django_db
|
||||
def test_card_photo_belongs_to_plant():
|
||||
from plants.models import PlantCardPhoto
|
||||
plant = Plant.objects.create(name='Test')
|
||||
photo = PlantCardPhoto.objects.create(plant=plant, image='plants/cards/test.jpg')
|
||||
assert photo.plant == plant
|
||||
|
||||
|
||||
@pytest.mark.django_db
|
||||
def test_card_photos_ordered_by_uploaded_at():
|
||||
from plants.models import PlantCardPhoto
|
||||
plant = Plant.objects.create(name='Test')
|
||||
p1 = PlantCardPhoto.objects.create(plant=plant, image='plants/cards/a.jpg')
|
||||
p2 = PlantCardPhoto.objects.create(plant=plant, image='plants/cards/b.jpg')
|
||||
qs = list(PlantCardPhoto.objects.filter(plant=plant))
|
||||
assert qs[0] == p1
|
||||
assert qs[1] == p2
|
||||
|
||||
|
||||
@pytest.mark.django_db
|
||||
def test_card_photos_deleted_with_plant():
|
||||
from plants.models import PlantCardPhoto
|
||||
plant = Plant.objects.create(name='Test')
|
||||
PlantCardPhoto.objects.create(plant=plant, image='plants/cards/test.jpg')
|
||||
plant.delete()
|
||||
assert PlantCardPhoto.objects.count() == 0
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue