diff --git a/pyproject.toml b/pyproject.toml index 3832c71..8814f07 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -33,6 +33,7 @@ dependencies = [ "whitenoise", "model_bakery", "markdown", + "Pillow", ] dynamic = ["version", "readme"] diff --git a/src/fellchensammlung/migrations/0004_image_adoptionnotice_photos_animal_photos.py b/src/fellchensammlung/migrations/0004_image_adoptionnotice_photos_animal_photos.py new file mode 100644 index 0000000..0320358 --- /dev/null +++ b/src/fellchensammlung/migrations/0004_image_adoptionnotice_photos_animal_photos.py @@ -0,0 +1,36 @@ +# Generated by Django 5.0.3 on 2024-03-18 16:08 + +import django.db.models.deletion +from django.conf import settings +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('fellchensammlung', '0003_markdowncontent'), + migrations.swappable_dependency(settings.AUTH_USER_MODEL), + ] + + operations = [ + migrations.CreateModel( + name='Image', + fields=[ + ('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), + ('title', models.CharField(max_length=200)), + ('image', models.ImageField(upload_to='images')), + ('alt_text', models.TextField(max_length=2000)), + ('uploaded_by', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to=settings.AUTH_USER_MODEL)), + ], + ), + migrations.AddField( + model_name='adoptionnotice', + name='photos', + field=models.ManyToManyField(blank=True, to='fellchensammlung.image'), + ), + migrations.AddField( + model_name='animal', + name='photos', + field=models.ManyToManyField(blank=True, to='fellchensammlung.image'), + ), + ] diff --git a/src/fellchensammlung/models.py b/src/fellchensammlung/models.py index 993bbac..ab0be54 100644 --- a/src/fellchensammlung/models.py +++ b/src/fellchensammlung/models.py @@ -1,7 +1,18 @@ from django.db import models +from django.contrib.auth.models import User from django.utils.translation import gettext_lazy as _ +class Image(models.Model): + title = models.CharField(max_length=200) + image = models.ImageField(upload_to='images') + alt_text = models.TextField(max_length=2000) + uploaded_by = models.ForeignKey(User, on_delete=models.CASCADE) + + def __str__(self): + return self.title + + class Species(models.Model): """Model representing a species of animal.""" name = models.CharField(max_length=200, help_text=_('Enter a animal species'), @@ -56,6 +67,7 @@ class Animal(models.Model): name = models.CharField(max_length=200) description = models.TextField(null=True, blank=True, verbose_name=_('Description')) species = models.ForeignKey(Species, on_delete=models.PROTECT) + photos = models.ManyToManyField(Image, blank=True) class AdoptionNotice(models.Model): @@ -71,6 +83,7 @@ class AdoptionNotice(models.Model): further_information = models.URLField(null=True, blank=True, verbose_name=_('Link to further information')) group_only = models.BooleanField(default=False, verbose_name=_('Only group adoption')) animals = models.ManyToManyField(Animal) + photos = models.ManyToManyField(Image, blank=True) class MarkdownContent(models.Model): @@ -85,4 +98,3 @@ class MarkdownContent(models.Model): def __str__(self): return self.title -