From c8dd7436fc6ad9da3b13061b86a5f26e5eacd533 Mon Sep 17 00:00:00 2001 From: moanos Date: Wed, 20 Mar 2024 16:40:52 +0100 Subject: [PATCH] feat: Add animal cards to adoption display --- .../migrations/0004_alter_animal_sex.py | 18 +++++++++++++++ src/fellchensammlung/models.py | 19 +++++++++++----- .../static/fellchensammlung/css/styles.css | 22 ++++++++++++++++++- .../detail_adoption_notice.html | 4 ++-- .../fellchensammlung/partial-animal-card.html | 13 +++++++++++ 5 files changed, 68 insertions(+), 8 deletions(-) create mode 100644 src/fellchensammlung/migrations/0004_alter_animal_sex.py create mode 100644 src/fellchensammlung/templates/fellchensammlung/partial-animal-card.html diff --git a/src/fellchensammlung/migrations/0004_alter_animal_sex.py b/src/fellchensammlung/migrations/0004_alter_animal_sex.py new file mode 100644 index 0000000..64fc4d1 --- /dev/null +++ b/src/fellchensammlung/migrations/0004_alter_animal_sex.py @@ -0,0 +1,18 @@ +# Generated by Django 5.0.3 on 2024-03-20 15:39 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('fellchensammlung', '0003_remove_image_uploaded_by'), + ] + + operations = [ + migrations.AlterField( + model_name='animal', + name='sex', + field=models.CharField(choices=[('M_N', 'neutered male'), ('M', 'male'), ('F_N', 'neutered female'), ('F', 'female')], max_length=20), + ), + ] diff --git a/src/fellchensammlung/models.py b/src/fellchensammlung/models.py index eda873a..d6c0a99 100644 --- a/src/fellchensammlung/models.py +++ b/src/fellchensammlung/models.py @@ -122,9 +122,9 @@ class Animal(models.Model): FEMALE_NEUTERED = "F_N" FEMALE = "F" SEX_CHOICES = { - MALE_NEUTERED: "male_neutered", + MALE_NEUTERED: "neutered male", MALE: "male", - FEMALE_NEUTERED: "female_neutered", + FEMALE_NEUTERED: "neutered female", FEMALE: "female", } @@ -148,9 +148,18 @@ class Animal(models.Model): """Returns a human-readable age based on the date of birth.""" return misc.age_as_hr_string(self.age) - @property - def photos_list(self): - """""" + def get_photo(self): + """ + Selects a random photo from the animal + """ + photos = self.photos.all() + if len(photos) > 0: + return photos[0] + + def get_photos(self): + """ + Selects all photos from the animal + """ return self.photos.all() def get_absolute_url(self): diff --git a/src/fellchensammlung/static/fellchensammlung/css/styles.css b/src/fellchensammlung/static/fellchensammlung/css/styles.css index 602b6f8..b1a1a8c 100644 --- a/src/fellchensammlung/static/fellchensammlung/css/styles.css +++ b/src/fellchensammlung/static/fellchensammlung/css/styles.css @@ -360,4 +360,24 @@ h1 { .card-adoption-notice img { max-width: 100%; border-radius: 10%; -} \ No newline at end of file +} + +.animals { + display: flex; + flex-wrap: wrap; + list-style-type:none; +} + +.card-animal { + flex: 1 16%; + margin: 10px; + border-radius: 3%; + border: 4px grey solid; + padding: 5px; +} + +.card-animal img { + max-width: 100%; + border-radius: 10%; + margin: 5px; +} diff --git a/src/fellchensammlung/templates/fellchensammlung/detail_adoption_notice.html b/src/fellchensammlung/templates/fellchensammlung/detail_adoption_notice.html index f185d8a..6de9038 100644 --- a/src/fellchensammlung/templates/fellchensammlung/detail_adoption_notice.html +++ b/src/fellchensammlung/templates/fellchensammlung/detail_adoption_notice.html @@ -19,9 +19,9 @@

{{ adoption_notice.description }}

-
+
{% for animal in adoption_notice.animals %} - {% include "fellchensammlung/detail-animal-partial.html" %} + {% include "fellchensammlung/partial-animal-card.html" %} {% endfor %}
{% endblock %} diff --git a/src/fellchensammlung/templates/fellchensammlung/partial-animal-card.html b/src/fellchensammlung/templates/fellchensammlung/partial-animal-card.html new file mode 100644 index 0000000..5908917 --- /dev/null +++ b/src/fellchensammlung/templates/fellchensammlung/partial-animal-card.html @@ -0,0 +1,13 @@ +
+
+

{{ animal.name }}

+
{{ animal.species }}
+
{{ animal.get_sex_display }}
+
+ {% if animal.get_photo %} + {{ animal.get_photo.alt_text }} +
+ {% else %} + No photos + {% endif %} +