feat: Add animal detail view
This commit is contained in:
parent
bc9df3ba8b
commit
dda400f3ba
19
src/fellchensammlung/migrations/0005_animal_sex.py
Normal file
19
src/fellchensammlung/migrations/0005_animal_sex.py
Normal file
@ -0,0 +1,19 @@
|
|||||||
|
# Generated by Django 5.0.3 on 2024-03-19 04:50
|
||||||
|
|
||||||
|
from django.db import migrations, models
|
||||||
|
|
||||||
|
|
||||||
|
class Migration(migrations.Migration):
|
||||||
|
|
||||||
|
dependencies = [
|
||||||
|
('fellchensammlung', '0004_image_adoptionnotice_photos_animal_photos'),
|
||||||
|
]
|
||||||
|
|
||||||
|
operations = [
|
||||||
|
migrations.AddField(
|
||||||
|
model_name='animal',
|
||||||
|
name='sex',
|
||||||
|
field=models.CharField(choices=[('M_N', 'male_neutered'), ('M', 'male'), ('F_N', 'female_neutered'), ('F', 'female')], default='female', max_length=20),
|
||||||
|
preserve_default=False,
|
||||||
|
),
|
||||||
|
]
|
@ -0,0 +1,20 @@
|
|||||||
|
# Generated by Django 5.0.3 on 2024-03-19 04:51
|
||||||
|
|
||||||
|
import datetime
|
||||||
|
from django.db import migrations, models
|
||||||
|
|
||||||
|
|
||||||
|
class Migration(migrations.Migration):
|
||||||
|
|
||||||
|
dependencies = [
|
||||||
|
('fellchensammlung', '0005_animal_sex'),
|
||||||
|
]
|
||||||
|
|
||||||
|
operations = [
|
||||||
|
migrations.AlterField(
|
||||||
|
model_name='animal',
|
||||||
|
name='date_of_birth',
|
||||||
|
field=models.DateField(default=datetime.datetime(2024, 3, 19, 4, 51, 44, 367516, tzinfo=datetime.timezone.utc), verbose_name='Date of birth'),
|
||||||
|
preserve_default=False,
|
||||||
|
),
|
||||||
|
]
|
@ -0,0 +1,23 @@
|
|||||||
|
{% extends "fellchensammlung/base_generic.html" %}
|
||||||
|
{% load custom_tags %}
|
||||||
|
{% load i18n %}
|
||||||
|
|
||||||
|
{% block content %}
|
||||||
|
<div class="detail-animal-header">
|
||||||
|
<h1 class="inline">{{ animal.name }}</h1>
|
||||||
|
<div class="species">{{ animal.species }}</div>
|
||||||
|
</div>
|
||||||
|
<div>
|
||||||
|
<table>
|
||||||
|
<tr>
|
||||||
|
<th>Alter</th>
|
||||||
|
<th>Geschlecht</th>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td>{{ animal.hr_age }}</td>
|
||||||
|
<td>{{ animal.sex }}</td>
|
||||||
|
</tr>
|
||||||
|
</table>
|
||||||
|
</div>
|
||||||
|
<p>{{ animal.description }}</p>
|
||||||
|
{% endblock %}
|
24
src/fellchensammlung/tools/misc.py
Normal file
24
src/fellchensammlung/tools/misc.py
Normal file
@ -0,0 +1,24 @@
|
|||||||
|
import datetime as datetime
|
||||||
|
|
||||||
|
|
||||||
|
def pluralize(number, letter="e"):
|
||||||
|
try:
|
||||||
|
size = len(number)
|
||||||
|
except TypeError:
|
||||||
|
size = int(number)
|
||||||
|
return '' if size == 1 else letter
|
||||||
|
|
||||||
|
|
||||||
|
def age_as_hr_string(age: datetime.timedelta) -> str:
|
||||||
|
days = age.days
|
||||||
|
weeks = age.days/7
|
||||||
|
months = age.days/30
|
||||||
|
years = age.days/365
|
||||||
|
if years >= 1:
|
||||||
|
return f'{years} Jahr{pluralize(years)} und {months} Monat{pluralize(months)}'
|
||||||
|
elif months >= 3:
|
||||||
|
return f'{months} Monat{pluralize(months)}'
|
||||||
|
elif weeks >= 3:
|
||||||
|
return f'{weeks} Woche{pluralize(weeks, "n")}'
|
||||||
|
else:
|
||||||
|
return f'{days} Tag{pluralize(days)}'
|
Loading…
Reference in New Issue
Block a user