diff --git a/tournaments/models/round.py b/tournaments/models/round.py index 0a8b2c0..236e0cb 100644 --- a/tournaments/models/round.py +++ b/tournaments/models/round.py @@ -35,13 +35,27 @@ class Round(models.Model): child_matches = child.match_set.all() if hide_empty_matches: - child_matches = [m for m in matches if m.should_appear()] + child_matches = [m for m in child_matches if m.should_appear()] matches.extend(child_matches) matches.extend(child.ranking_matches(hide_empty_matches)) return matches def all_matches(self): - matches = list(self.match_set.all()) - matches.extend(self.ranking_matches(True)) + matches = [] + matches.extend(self.match_set.all()) + matches.extend(self.get_matches_recursive(False)) + return matches + + def get_matches_recursive(self, hide_empty_matches): + matches = list(self.match_set.all()) # Retrieve matches associated with the current round + if hide_empty_matches: + matches = [m for m in matches if m.should_appear()] + + # Recursively fetch matches from child rounds + for child_round in self.children.all(): + matches.extend(child_round.get_matches_recursive(hide_empty_matches)) + + # print(f"{self.name()} > COUNT REC = {len(matches)}") + return matches diff --git a/tournaments/models/tournament.py b/tournaments/models/tournament.py index 7423bfc..ac55ab5 100644 --- a/tournaments/models/tournament.py +++ b/tournaments/models/tournament.py @@ -175,8 +175,8 @@ class Tournament(models.Model): previous_round = self.round_for_index(current_round.index + 1) if previous_round: - matches.extend(current_round.all_matches()) - matches.extend(previous_round.all_matches()) + matches.extend(current_round.get_matches_recursive(False)) + matches.extend(previous_round.get_matches_recursive(False)) else: matches.extend(current_round.all_matches()) group_stages = self.live_group_stages() @@ -199,7 +199,7 @@ class Tournament(models.Model): return matches[0] def round_for_index(self, index): - return self.round_set.filter(index=index).first() + return self.round_set.filter(index=index,loser=None).first() def group_stages_matches(self): matches = []