mirror of
https://gitlab.com/animath/si/plateforme.git
synced 2024-12-25 06:22:22 +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():
|
if qs.exists():
|
||||||
return qs.get()
|
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:
|
class Meta:
|
||||||
verbose_name = _("tournament")
|
verbose_name = _("tournament")
|
||||||
verbose_name_plural = _("tournaments")
|
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):
|
class Participation(models.Model):
|
||||||
"""
|
"""
|
||||||
The Participation model contains all data that are related to the participation:
|
The Participation model contains all data that are related to the participation:
|
||||||
@ -266,6 +262,40 @@ class Participation(models.Model):
|
|||||||
verbose_name_plural = _("participations")
|
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):
|
class Solution(models.Model):
|
||||||
participation = models.ForeignKey(
|
participation = models.ForeignKey(
|
||||||
Participation,
|
Participation,
|
||||||
@ -307,6 +337,7 @@ class Synthesis(models.Model):
|
|||||||
pool = models.ForeignKey(
|
pool = models.ForeignKey(
|
||||||
Pool,
|
Pool,
|
||||||
on_delete=models.CASCADE,
|
on_delete=models.CASCADE,
|
||||||
|
related_name="syntheses",
|
||||||
verbose_name=_("pool"),
|
verbose_name=_("pool"),
|
||||||
)
|
)
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user