From 2783f4181f6b24b7be59d28310bb9e767116f139 Mon Sep 17 00:00:00 2001 From: Laurent Date: Sun, 22 Dec 2024 11:24:25 +0100 Subject: [PATCH] Fix crash --- tournaments/models/tournament.py | 23 +++++++++++++---------- 1 file changed, 13 insertions(+), 10 deletions(-) diff --git a/tournaments/models/tournament.py b/tournaments/models/tournament.py index 90c5244..c844917 100644 --- a/tournaments/models/tournament.py +++ b/tournaments/models/tournament.py @@ -690,17 +690,20 @@ class Tournament(models.Model): # all started matches have ended, possibly last_finished_match = self.last_finished_match() - # print(f'last_finished_match = {last_finished_match.name}') - round_root_index = last_finished_match.round.root_round().index - # print(f'round_index = {round_root_index}') - if round_root_index == 0: - return last_finished_match.round - else: - round = self.round_set.filter(parent=None,index=round_root_index-1).first() - if round: - return round + if last_finished_match: + # print(f'last_finished_match = {last_finished_match.name}') + round_root_index = last_finished_match.round.root_round().index + # print(f'round_index = {round_root_index}') + if round_root_index == 0: + return last_finished_match.round else: - return None + round = self.round_set.filter(parent=None,index=round_root_index-1).first() + if round: + return round + else: + return None + else: + return None def last_started_match(self): matches = [m for m in self.all_matches(False) if m.start_date]