feat: add Location.cover_photo ImageField + migration + test

This commit is contained in:
Stephan Kerkman 2026-06-01 16:40:59 +02:00
parent ea627ad4ef
commit 2d7ca494bd
4 changed files with 36 additions and 1 deletions

View file

@ -0,0 +1,18 @@
# Generated by Django 5.2.1 on 2026-06-01 14:40
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('plants', '0010_add_frost_density_to_species'),
]
operations = [
migrations.AddField(
model_name='location',
name='cover_photo',
field=models.ImageField(blank=True, null=True, upload_to='locations/'),
),
]

View file

@ -3,6 +3,7 @@ from django.db import models
class Location(models.Model): class Location(models.Model):
name = models.CharField(max_length=200, unique=True) name = models.CharField(max_length=200, unique=True)
cover_photo = models.ImageField(upload_to='locations/', blank=True, null=True)
class Meta: class Meta:
ordering = ['name'] ordering = ['name']

View file

@ -0,0 +1,16 @@
import pytest
from django.core.files.uploadedfile import SimpleUploadedFile
from plants.models import Location
@pytest.mark.django_db
def test_location_cover_photo_field_exists():
"""Location can be saved with and without a cover_photo."""
loc = Location.objects.create(name='Test Garden')
assert loc.cover_photo.name == '' or loc.cover_photo.name is None
fake_img = SimpleUploadedFile('cover.jpg', b'fake-image-data', content_type='image/jpeg')
loc.cover_photo = fake_img
loc.save()
loc.refresh_from_db()
assert loc.cover_photo.name.startswith('locations/')

View file

@ -1,2 +1,2 @@
[pytest] [pytest]
DJANGO_SETTINGS_MODULE = plantdb.settings DJANGO_SETTINGS_MODULE = bloombase.settings