diff --git a/tournaments/migrations/0081_round_group_stage_loser_bracket.py b/tournaments/migrations/0081_round_group_stage_loser_bracket.py new file mode 100644 index 0000000..233a29a --- /dev/null +++ b/tournaments/migrations/0081_round_group_stage_loser_bracket.py @@ -0,0 +1,18 @@ +# Generated by Django 4.2.11 on 2024-09-09 11:57 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('tournaments', '0080_alter_club_acronym'), + ] + + operations = [ + migrations.AddField( + model_name='round', + name='group_stage_loser_bracket', + field=models.BooleanField(default=False), + ), + ] diff --git a/tournaments/models/round.py b/tournaments/models/round.py index 5797f80..0ad10e3 100644 --- a/tournaments/models/round.py +++ b/tournaments/models/round.py @@ -9,6 +9,7 @@ class Round(models.Model): parent = 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) start_date = models.DateTimeField(null=True, blank=True) + group_stage_loser_bracket = models.BooleanField(default=False) def __str__(self): if self.parent: @@ -23,6 +24,8 @@ class Round(models.Model): def name(self): if self.parent: return "Matchs de classement" + elif self.group_stage_loser_bracket is True: + return "Matchs de classement de poule" else: if self.index == 0: return "Finale" diff --git a/tournaments/models/tournament.py b/tournaments/models/tournament.py index 4fd6320..3627af7 100644 --- a/tournaments/models/tournament.py +++ b/tournaments/models/tournament.py @@ -542,6 +542,14 @@ class Tournament(models.Model): matches.extend(group_stage.match_set.all()) matches = [m for m in matches if m.should_appear()] matches.sort(key=lambda m: (m.start_date is None, m.end_date is not None, m.start_date, m.index)) + + group_stage_loser_bracket = list(self.round_set.filter(parent=None, group_stage_loser_bracket=True).all()) + if len(group_stage_loser_bracket) > 0: + loser_matches = group_stage_loser_bracket[0].all_matches(True) + loser_matches = [m for m in loser_matches if m.should_appear()] + loser_matches.sort(key=lambda m: (m.start_date is None, m.end_date is not None, m.start_date, m.index)) + matches.extend(loser_matches) + return matches def elected_broadcast_group_stages(self): diff --git a/tournaments/views.py b/tournaments/views.py index c79a66b..c250025 100644 --- a/tournaments/views.py +++ b/tournaments/views.py @@ -136,7 +136,11 @@ def tournament(request, tournament_id): group_stage_id = request.GET.get('group_stage') match_groups = tournament.match_groups(False, group_stage_id, round_id) - rounds = tournament.round_set.filter(parent=None).order_by('-index') + + bracket_rounds = tournament.round_set.filter(parent=None, group_stage_loser_bracket=False).order_by('-index') + rounds = list(tournament.round_set.filter(group_stage_loser_bracket=True)) + rounds.extend(bracket_rounds) + group_stages = tournament.groupstage_set.order_by('index') print(len(match_groups))