feat: add sex coding

This commit is contained in:
moanos [he/him] 2024-11-09 10:03:04 +01:00
parent 98d67381c6
commit 2212df4729

View File

@ -217,6 +217,24 @@ class AdoptionNotice(models.Model):
def animals(self):
return Animal.objects.filter(adoption_notice=self)
@property
def sexes(self):
sexes = set()
for animal in self.animals:
sexes.update(animal.sex)
return sexes
def sex_code(self):
if len(self.sexes) > 1:
return "mixed"
elif self.sexes.pop() == Animal.MALE:
return "male"
elif self.sexes.pop() == Animal.FEMALE:
return "female"
else:
return "mixed"
@property
def comments(self):
return Comment.objects.filter(adoption_notice=self)
@ -421,7 +439,6 @@ class AdoptionNoticeStatus(models.Model):
self.save()
class Animal(models.Model):
MALE_NEUTERED = "M_N"
MALE = "M"
@ -565,7 +582,6 @@ class ModerationAction(models.Model):
private_comment = models.TextField(blank=True)
report = models.ForeignKey(Report, on_delete=models.CASCADE)
def __str__(self):
return f"[{self.action}]: {self.public_comment}"