diff --git a/tournaments/models/round.py b/tournaments/models/round.py index 1f5d43a..195e9e3 100644 --- a/tournaments/models/round.py +++ b/tournaments/models/round.py @@ -56,7 +56,7 @@ class Round(TournamentSubModel): def ranking_matches(self, hide_empty_matches): - children_with_matches = self.children.prefetch_related('matches') + children_with_matches = self.children.prefetch_related('matches', 'matches__team_scores', 'matches__team_scores__team_registration', 'matches__team_scores__team_registration__player_registrations') matches = [] for child in children_with_matches: diff --git a/tournaments/models/team_registration.py b/tournaments/models/team_registration.py index 02ad873..a52bb0c 100644 --- a/tournaments/models/team_registration.py +++ b/tournaments/models/team_registration.py @@ -83,15 +83,14 @@ class TeamRegistration(TournamentSubModel): else: return ['Place réservée'] elif player_count == 1: - players = list(self.players_sorted_by_rank) + players = self.players_sorted_by_rank return [players[0].shortened_name(forced=forced)] else: - players = list(self.players_sorted_by_rank) + players = self.players_sorted_by_rank return [pr.shortened_name(forced=forced) for pr in players] @property def players_sorted_by_rank(self): - # Fetch related PlayerRegistration objects return self.player_registrations.all().order_by('rank') def player_names(self): diff --git a/tournaments/models/tournament.py b/tournaments/models/tournament.py index de27e40..5780cfa 100644 --- a/tournaments/models/tournament.py +++ b/tournaments/models/tournament.py @@ -518,12 +518,12 @@ class Tournament(BaseModel): groups = [] if self.display_matches(): - rounds = self.rounds.filter(parent=None, group_stage_loser_bracket=False).all().order_by('index').prefetch_related('matches') + rounds = self.rounds.filter(parent=None, group_stage_loser_bracket=False).all().order_by('index').prefetch_related('matches', 'matches__team_scores', 'matches__team_scores__team_registration', 'matches__team_scores__team_registration__player_registrations') for round in rounds: groups.extend(self.round_match_groups(round, broadcasted, hide_empty_matches=True)) if self.display_group_stages(): - rounds = self.rounds.filter(parent=None, group_stage_loser_bracket=True).all().order_by('index').prefetch_related('matches') + rounds = self.rounds.filter(parent=None, group_stage_loser_bracket=True).all().order_by('index').prefetch_related('matches', 'matches__team_scores', 'matches__team_scores__team_registration', 'matches__team_scores__team_registration__player_registrations') for round in rounds: groups.extend(self.round_match_groups(round, broadcasted, hide_empty_matches=True)) @@ -610,7 +610,7 @@ class Tournament(BaseModel): def sorted_group_stages(self): # Get all group stages and sort by step (descending) and index (ascending) - group_stages = self.group_stages.all().order_by('-step', 'index').prefetch_related('matches') + group_stages = self.group_stages.all().order_by('-step', 'index').prefetch_related('matches', 'matches__team_scores', 'matches__team_scores__team_registration', 'matches__team_scores__team_registration__player_registrations') # List to collect live group stages from finished steps filtered = []