feat: Add image basics

This commit is contained in:
moanos [he/him] 2024-03-18 17:10:48 +01:00
parent 57a483df24
commit 15e1d65089
3 changed files with 50 additions and 1 deletions

View File

@ -33,6 +33,7 @@ dependencies = [
"whitenoise", "whitenoise",
"model_bakery", "model_bakery",
"markdown", "markdown",
"Pillow",
] ]
dynamic = ["version", "readme"] dynamic = ["version", "readme"]

View File

@ -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'),
),
]

View File

@ -1,7 +1,18 @@
from django.db import models from django.db import models
from django.contrib.auth.models import User
from django.utils.translation import gettext_lazy as _ 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): class Species(models.Model):
"""Model representing a species of animal.""" """Model representing a species of animal."""
name = models.CharField(max_length=200, help_text=_('Enter a animal species'), 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) name = models.CharField(max_length=200)
description = models.TextField(null=True, blank=True, verbose_name=_('Description')) description = models.TextField(null=True, blank=True, verbose_name=_('Description'))
species = models.ForeignKey(Species, on_delete=models.PROTECT) species = models.ForeignKey(Species, on_delete=models.PROTECT)
photos = models.ManyToManyField(Image, blank=True)
class AdoptionNotice(models.Model): 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')) 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')) group_only = models.BooleanField(default=False, verbose_name=_('Only group adoption'))
animals = models.ManyToManyField(Animal) animals = models.ManyToManyField(Animal)
photos = models.ManyToManyField(Image, blank=True)
class MarkdownContent(models.Model): class MarkdownContent(models.Model):
@ -85,4 +98,3 @@ class MarkdownContent(models.Model):
def __str__(self): def __str__(self):
return self.title return self.title