diff --git a/tournaments/models.py b/tournaments/models.py index 2f07a3e..c1df3d9 100644 --- a/tournaments/models.py +++ b/tournaments/models.py @@ -281,9 +281,8 @@ class Match(models.Model): _minutes = int((_seconds % 3600) / 60) return f"{_hours:02d}h{_minutes:02d}min" - def seconds(self): - return (timezone.now() - self.date).total_seconds() - + # def seconds(self): + # return (timezone.now() - self.start_date).total_seconds() def live_match(self): title = f"{self.index}" @@ -293,9 +292,18 @@ class Match(models.Model): livematch = LiveMatch(title, date, duration) for team_state in self.team_states: + + image = team_state.team_registration.logo + names = team_state.team_names() + scores = team_state.score + weight = team_state.weight + is_winner = False + team = Team(image, names, scores, weight, is_winner) + + break - # def __init__(self, names, date, weight, stage, image): + # def __init__(self, image, names, scores, weight, is_winner): @@ -373,6 +381,7 @@ class TeamState(models.Model): id = models.UUIDField(primary_key=True, default=uuid.uuid4, editable=False) match = models.ForeignKey(Match, on_delete=models.CASCADE, related_name="team_states") player_registrations = models.ManyToManyField(PlayerRegistration, blank=True) + team_registration = models.ForeignKey(Match, on_delete=models.CASCADE) score = models.CharField(max_length=50, null=True, blank=True) walk_out = models.IntegerField(null=True, blank=True) #id, int of the walked_out team lucky_loser = models.BooleanField() @@ -384,14 +393,19 @@ class TeamState(models.Model): names = map(lambda player: player.name(), self.player_registrations.all()) return " - ".join(names) - def team_name(self): - + def team_names(self): + names = [] + if self.team_registration.name: + names.append(self.team_registration.name) + else: + names = self.player_names() class Team: - def __init__(self, image, names, scores, is_winner): + def __init__(self, image, names, scores, weight, is_winner): self.image = image self.names = [] self.scores = [] + self.weight = weight self.is_winner = is_winner def add_names(self, name):