You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
padelclub_backend/tournaments/models/round.py

52 lines
1.9 KiB

from django.db import models
from . import Tournament, FederalMatchCategory
import uuid
class Round(models.Model):
id = models.UUIDField(primary_key=True, default=uuid.uuid4, editable=True)
tournament = models.ForeignKey(Tournament, on_delete=models.CASCADE)
index = models.IntegerField(default=0)
loser = models.ForeignKey('self', blank=True, null=True, on_delete=models.CASCADE, related_name='children')
format = models.IntegerField(default=FederalMatchCategory.NINE_GAMES, choices=FederalMatchCategory.choices, null=True, blank=True)
def __str__(self):
if self.loser:
return f"{self.tournament.name} - Loser bracket of : {self.name()}"
else:
return f"{self.tournament.name} - {self.name()}"
# def stage_call(self):
# stage_call = StageCall(f"1/{self.index}")
# for match in self.match_set.all():
# names = map(lambda ts: ts.player_names(), match.teamstate_set.all())
# if names:
# team_call = TeamCall(names, match.formatted_start_date)
# stage_call.add_team(team_call)
# return stage_call
def name(self):
if self.loser:
return "Matchs de classement"
else:
if self.index == 0:
return "Finale"
elif self.index == 1:
return "Demi-Finales"
elif self.index == 2:
return "Quarts de finale"
else:
squared = 2 ** self.index
return f"{squared}ème"
def ranking_matches(self, hide_empty_matches):
matches = []
for child in self.children.all():
child_matches = child.match_set.all()
if hide_empty_matches:
child_matches = [m for m in matches if m.should_appear()]
matches.extend(child_matches)
matches.extend(child.ranking_matches(hide_empty_matches))
return matches