mirror of
https://gitlab.com/animath/si/plateforme.git
synced 2024-12-24 17:02:24 +00:00
Add some properties to the models
This commit is contained in:
parent
ad1337209d
commit
f5ec9d1054
@ -171,6 +171,24 @@ class Tournament(models.Model):
|
||||
if qs.exists():
|
||||
return qs.get()
|
||||
|
||||
@property
|
||||
def participations(self):
|
||||
if self.final:
|
||||
return Participation.objects.filter(final=True)
|
||||
return self.participation_set
|
||||
|
||||
@property
|
||||
def solutions(self):
|
||||
if self.final:
|
||||
return Solution.objects.filter(final_solution=True)
|
||||
return Solution.objects.filter(participation__tournament=self)
|
||||
|
||||
@property
|
||||
def syntheses(self):
|
||||
if self.final:
|
||||
return Synthesis.objects.filter(final_solution=True)
|
||||
return Synthesis.objects.filter(participation__tournament=self)
|
||||
|
||||
class Meta:
|
||||
verbose_name = _("tournament")
|
||||
verbose_name_plural = _("tournaments")
|
||||
@ -179,28 +197,6 @@ class Tournament(models.Model):
|
||||
]
|
||||
|
||||
|
||||
class Pool(models.Model):
|
||||
tournament = models.ForeignKey(
|
||||
Tournament,
|
||||
on_delete=models.CASCADE,
|
||||
verbose_name=_("tournament"),
|
||||
)
|
||||
|
||||
round = models.PositiveSmallIntegerField(
|
||||
verbose_name=_("round"),
|
||||
)
|
||||
|
||||
juries = models.ManyToManyField(
|
||||
VolunteerRegistration,
|
||||
verbose_name=_("juries"),
|
||||
related_name="jury_in",
|
||||
)
|
||||
|
||||
class Meta:
|
||||
verbose_name = _("pool")
|
||||
verbose_name_plural = _("pools")
|
||||
|
||||
|
||||
class Participation(models.Model):
|
||||
"""
|
||||
The Participation model contains all data that are related to the participation:
|
||||
@ -266,6 +262,40 @@ class Participation(models.Model):
|
||||
verbose_name_plural = _("participations")
|
||||
|
||||
|
||||
class Pool(models.Model):
|
||||
tournament = models.ForeignKey(
|
||||
Tournament,
|
||||
on_delete=models.CASCADE,
|
||||
related_name="pools",
|
||||
verbose_name=_("tournament"),
|
||||
)
|
||||
|
||||
round = models.PositiveSmallIntegerField(
|
||||
verbose_name=_("round"),
|
||||
)
|
||||
|
||||
participations = models.ManyToManyField(
|
||||
Participation,
|
||||
related_name="pools",
|
||||
verbose_name=_("participations"),
|
||||
)
|
||||
|
||||
juries = models.ManyToManyField(
|
||||
VolunteerRegistration,
|
||||
related_name="jury_in",
|
||||
verbose_name=_("juries"),
|
||||
)
|
||||
|
||||
@property
|
||||
def solutions(self):
|
||||
return Solution.objects.filter(participation__in=self.participations, final_solution=self.tournament.final)
|
||||
|
||||
class Meta:
|
||||
verbose_name = _("pool")
|
||||
verbose_name_plural = _("pools")
|
||||
|
||||
|
||||
|
||||
class Solution(models.Model):
|
||||
participation = models.ForeignKey(
|
||||
Participation,
|
||||
@ -307,6 +337,7 @@ class Synthesis(models.Model):
|
||||
pool = models.ForeignKey(
|
||||
Pool,
|
||||
on_delete=models.CASCADE,
|
||||
related_name="syntheses",
|
||||
verbose_name=_("pool"),
|
||||
)
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user