feat: Add animal detail view
This commit is contained in:
parent
029e974079
commit
bc9df3ba8b
@ -2,6 +2,9 @@ from django.db import models
|
|||||||
from django.urls import reverse
|
from django.urls import reverse
|
||||||
from django.contrib.auth.models import User
|
from django.contrib.auth.models import User
|
||||||
from django.utils.translation import gettext_lazy as _
|
from django.utils.translation import gettext_lazy as _
|
||||||
|
from datetime import datetime
|
||||||
|
|
||||||
|
from fellchensammlung.tools import misc
|
||||||
|
|
||||||
|
|
||||||
class Image(models.Model):
|
class Image(models.Model):
|
||||||
@ -61,18 +64,39 @@ class RescueOrganization(models.Model):
|
|||||||
|
|
||||||
|
|
||||||
class Animal(models.Model):
|
class Animal(models.Model):
|
||||||
def __str__(self):
|
MALE_NEUTERED = "M_N"
|
||||||
return f"{self.name}"
|
MALE = "M"
|
||||||
|
FEMALE_NEUTERED = "F_N"
|
||||||
|
FEMALE = "F"
|
||||||
|
SEX_CHOICES = {
|
||||||
|
MALE_NEUTERED: "male_neutered",
|
||||||
|
MALE: "male",
|
||||||
|
FEMALE_NEUTERED: "female_neutered",
|
||||||
|
FEMALE: "female",
|
||||||
|
}
|
||||||
|
|
||||||
def get_absolute_url(self):
|
date_of_birth = models.DateField(verbose_name=_('Date of birth'))
|
||||||
"""Returns the url to access a detailed page for the animal."""
|
|
||||||
return reverse('animal-detail', args=[str(self.id)])
|
|
||||||
|
|
||||||
date_of_birth = models.DateField(null=True, blank=True, verbose_name=_('Date of birth'))
|
|
||||||
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)
|
photos = models.ManyToManyField(Image, blank=True)
|
||||||
|
sex = models.CharField(max_length=20, choices=SEX_CHOICES, )
|
||||||
|
|
||||||
|
def __str__(self):
|
||||||
|
return f"{self.name}"
|
||||||
|
|
||||||
|
@property
|
||||||
|
def age(self):
|
||||||
|
return datetime.today().date() - self.date_of_birth
|
||||||
|
|
||||||
|
@property
|
||||||
|
def hr_age(self):
|
||||||
|
"""Returns a human-readable age based on the date of birth."""
|
||||||
|
return misc.age_as_hr_string(self.age)
|
||||||
|
|
||||||
|
def get_absolute_url(self):
|
||||||
|
"""Returns the url to access a detailed page for the animal."""
|
||||||
|
return reverse('animal-detail', args=[str(self.id)])
|
||||||
|
|
||||||
|
|
||||||
class AdoptionNotice(models.Model):
|
class AdoptionNotice(models.Model):
|
||||||
|
@ -282,3 +282,20 @@ h1 {
|
|||||||
-webkit-transform: scale(1, 1);
|
-webkit-transform: scale(1, 1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.detail-animal-header {
|
||||||
|
border: 2px lavender solid;
|
||||||
|
border-radius: 5px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.species {
|
||||||
|
display: inline;
|
||||||
|
border: darkgray 2px solid;
|
||||||
|
border-radius: 0.3rem;
|
||||||
|
background: aliceblue;
|
||||||
|
padding: 2px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.inline {
|
||||||
|
display: inline;
|
||||||
|
}
|
@ -2,7 +2,7 @@ from django.shortcuts import render
|
|||||||
import markdown
|
import markdown
|
||||||
|
|
||||||
from django.http import HttpResponse
|
from django.http import HttpResponse
|
||||||
from fellchensammlung.models import AdoptionNotice, MarkdownContent
|
from fellchensammlung.models import AdoptionNotice, MarkdownContent, Animal
|
||||||
|
|
||||||
|
|
||||||
def index(request):
|
def index(request):
|
||||||
@ -18,8 +18,9 @@ def adoption_notice_detail(request, adoption_notice_id):
|
|||||||
|
|
||||||
|
|
||||||
def animal_detail(request, animal_id):
|
def animal_detail(request, animal_id):
|
||||||
response = "You're looking at animal %s."
|
animal = Animal.objects.get(id=animal_id)
|
||||||
return HttpResponse(response % animal_id)
|
context = {"animal": animal}
|
||||||
|
return render(request, 'fellchensammlung/detail_animal.html', context=context)
|
||||||
|
|
||||||
def search(request):
|
def search(request):
|
||||||
latest_adoption_list = AdoptionNotice.objects.order_by("-created_at")[:5]
|
latest_adoption_list = AdoptionNotice.objects.order_by("-created_at")[:5]
|
||||||
|
Loading…
Reference in New Issue
Block a user