feat: add Location.cover_photo ImageField + migration + test
This commit is contained in:
parent
ea627ad4ef
commit
2d7ca494bd
4 changed files with 36 additions and 1 deletions
18
plants/migrations/0011_location_cover_photo.py
Normal file
18
plants/migrations/0011_location_cover_photo.py
Normal 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/'),
|
||||||
|
),
|
||||||
|
]
|
||||||
|
|
@ -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']
|
||||||
|
|
|
||||||
16
plants/tests/test_location_redesign.py
Normal file
16
plants/tests/test_location_redesign.py
Normal 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/')
|
||||||
|
|
@ -1,2 +1,2 @@
|
||||||
[pytest]
|
[pytest]
|
||||||
DJANGO_SETTINGS_MODULE = plantdb.settings
|
DJANGO_SETTINGS_MODULE = bloombase.settings
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue