You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
38 lines
1.5 KiB
38 lines
1.5 KiB
from django.db import models
|
|
from . import Match, TeamRegistration, PlayerRegistration
|
|
import uuid
|
|
|
|
class TeamScore(models.Model):
|
|
id = models.UUIDField(primary_key=True, default=uuid.uuid4, editable=True)
|
|
match = models.ForeignKey(Match, on_delete=models.CASCADE, related_name="team_scores")
|
|
team_registration = models.ForeignKey(TeamRegistration, on_delete=models.CASCADE, null=True, blank=True)
|
|
player_registrations = models.ManyToManyField(PlayerRegistration, blank=True)
|
|
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()
|
|
|
|
def __str__(self):
|
|
return f"{str(self.match)}: {self.player_names()}"
|
|
|
|
def player_names(self):
|
|
names = map(lambda player: player.name(), self.player_registrations.all())
|
|
return " - ".join(names)
|
|
|
|
def team_names(self):
|
|
names = []
|
|
if self.team_registration.name:
|
|
names.append(self.team_registration.name)
|
|
else:
|
|
names = list(map(lambda player: player.name(), self.player_registrations.all()))
|
|
return names
|
|
|
|
def scores(self):
|
|
return [int(x) for x in self.score.split(',')]
|
|
|
|
def scores_array(self):
|
|
scores = []
|
|
if self.score:
|
|
scores = [x for x in self.score.split(',')]
|
|
if self.walk_out == 1:
|
|
scores.insert(0, 'WO')
|
|
return scores
|
|
|