diff --git a/tournaments/models/club.py b/tournaments/models/club.py index f371b0b..ddfb821 100644 --- a/tournaments/models/club.py +++ b/tournaments/models/club.py @@ -21,3 +21,9 @@ class Club(models.Model): def events_count(self): return len(self.event_set.all()) + + def court_name(self, index): + for court in self.court_set.all(): + if court.index == index and court.name: + return court.name + return f"Terrain {index}" diff --git a/tournaments/models/court.py b/tournaments/models/court.py index 1e9e24c..d0b4de0 100644 --- a/tournaments/models/court.py +++ b/tournaments/models/court.py @@ -9,3 +9,9 @@ class Court(models.Model): name = models.CharField(max_length=50, null=True, blank=True) exit_allowed = models.BooleanField(default=False) indoor = models.BooleanField(default=False) + + def __str__(self): + if self.name: + return self.name + else: + return f"Terrain {self.index}" diff --git a/tournaments/models/match.py b/tournaments/models/match.py index b4c42a0..c46b85d 100644 --- a/tournaments/models/match.py +++ b/tournaments/models/match.py @@ -25,13 +25,14 @@ class Match(models.Model): names = " / ".join(self.player_names()) return f"{self.stage_name()} #{self.index}: {names}" - # player_names = " / ".join(self.player_names()) - # if self.round: - # return f"{match_name} > {player_names}" - # elif self.group_stage: - # return f"{match_name} > {player_names}" - # else: - # return "--" + def tournament(self): + if self.round: + return self.round.tournament + else: + return self.group_stage.tournament + + def court_name(self, index): + return self.tournament().event.club.court_name(index) def backup_name(self): items = [] @@ -109,16 +110,11 @@ class Match(models.Model): _minutes = int((_seconds % 3600) / 60) return f"{_hours:02d}h{_minutes:02d}min" - # def seconds(self): - # return (timezone.now() - self.start_date).total_seconds() - def live_match(self): title = self.name if self.name else self.backup_name() date = self.formatted_start_date() duration = self.time_indication() - court = "" - if self.court: - court = f"Terrain {self.court}" + court = self.court_name(self.court_index) ended = self.end_date is not None livematch = LiveMatch(title, date, duration, court, self.started(), ended) diff --git a/tournaments/models/player_registration.py b/tournaments/models/player_registration.py index 3087151..8022ed7 100644 --- a/tournaments/models/player_registration.py +++ b/tournaments/models/player_registration.py @@ -34,7 +34,6 @@ class PlayerRegistration(models.Model): source = models.IntegerField(choices=PlayerDataSource.choices, null=True, blank=True) has_arrived = models.BooleanField(default=False) - def __str__(self): return self.name() diff --git a/tournaments/models/tournament.py b/tournaments/models/tournament.py index cbb49b2..6ceb20d 100644 --- a/tournaments/models/tournament.py +++ b/tournaments/models/tournament.py @@ -107,7 +107,7 @@ class Tournament(models.Model): matches = [m for m in matches if m.should_appear()] if matches: - return self.create_match_group(group_stage.name(), matches, broadcasted) + return self.create_match_group(group_stage.display_name(), matches, broadcasted) else: return None