feat: Use text choices for sex

This commit is contained in:
moanos [he/him] 2024-11-21 20:25:59 +01:00
parent 3eb7dbe984
commit 052e42f76a

View File

@ -246,9 +246,9 @@ class AdoptionNotice(models.Model):
def sex_code(self): def sex_code(self):
if len(self.sexes) > 1: if len(self.sexes) > 1:
return "mixed" return "mixed"
elif self.sexes.pop() == Animal.MALE: elif self.sexes.pop() == SexChoices.MALE:
return "male" return "male"
elif self.sexes.pop() == Animal.FEMALE: elif self.sexes.pop() == SexChoices.FEMALE:
return "female" return "female"
else: else:
return "mixed" return "mixed"
@ -457,24 +457,23 @@ class AdoptionNoticeStatus(models.Model):
self.save() self.save()
class Animal(models.Model): class SexChoices(models.TextChoices):
MALE_NEUTERED = "M_N" MALE_NEUTERED = "M_N", "neutered male"
MALE = "M" MALE = "M", "male"
FEMALE_NEUTERED = "F_N" FEMALE_NEUTERED = "F_N", "neutered female"
FEMALE = "F" FEMALE = "F", "female"
SEX_CHOICES = {
MALE_NEUTERED: "neutered male",
MALE: "male",
FEMALE_NEUTERED: "neutered female",
FEMALE: "female",
}
class Animal(models.Model):
date_of_birth = models.DateField(verbose_name=_('Geburtsdatum')) date_of_birth = models.DateField(verbose_name=_('Geburtsdatum'))
name = models.CharField(max_length=200) name = models.CharField(max_length=200)
description = models.TextField(null=True, blank=True, verbose_name=_('Beschreibung')) description = models.TextField(null=True, blank=True, verbose_name=_('Beschreibung'))
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, ) sex = models.CharField(
max_length=20,
choices=SexChoices.choices,
)
adoption_notice = models.ForeignKey(AdoptionNotice, on_delete=models.CASCADE) adoption_notice = models.ForeignKey(AdoptionNotice, on_delete=models.CASCADE)
owner = models.ForeignKey(User, on_delete=models.CASCADE) owner = models.ForeignKey(User, on_delete=models.CASCADE)
updated_at = models.DateTimeField(auto_now=True) updated_at = models.DateTimeField(auto_now=True)