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.
 
 
 
 
padelclub_backend/tournaments/models/team_registration.py

57 lines
2.4 KiB

from django.db import models
from . import Tournament, GroupStage
import uuid
class TeamRegistration(models.Model):
id = models.UUIDField(primary_key=True, default=uuid.uuid4, editable=True)
tournament = models.ForeignKey(Tournament, on_delete=models.CASCADE)
group_stage = models.ForeignKey(GroupStage, null=True, blank=True, on_delete=models.SET_NULL)
registration_date = models.DateTimeField(null=True, blank=True)
call_date = models.DateTimeField(null=True, blank=True)
bracket_position = models.IntegerField(null=True, blank=True)
group_stage_position = models.IntegerField(null=True, blank=True)
comment = models.CharField(max_length=200, null=True, blank=True)
source = models.CharField(max_length=20, null=True, blank=True)
source_value = models.CharField(max_length=200, null=True, blank=True)
logo = models.CharField(max_length=200, null=True, blank=True) #models.FilePathField(path=os.path.join(settings.STATIC_ROOT, "images"), null=True, blank=True)
name = models.CharField(max_length=200, null=True, blank=True)
def __str__(self):
return self.player_names()
def team_names(self):
if self.name:
return [self.name]
else:
return map(lambda pr: pr.name(), self.playerregistration_set.all())
def player_names(self):
names = map(lambda pr: pr.name(), self.playerregistration_set.all())
str = " - ".join(names)
if len(str) > 0:
return str
else:
return "no players"
def next_stage(self):
matches = map(lambda ts: ts.match, self.teamscore_set.all())
matches = [m for m in matches if m.group_stage is None]
matches = sorted(matches, key=lambda m: m.round.index)
# matches = self.teamscore_set
# matches = Match.objects.filter(group_stage__isnull=True, team_scores__player_registrations__id=self.id).order_by('round__index')
print(f"matches = {len(matches)}")
if matches:
return matches[0].round.name()
elif self.group_stage:
return self.group_stage.name()
else:
return "--"
def weight(self):
top_two_players = self.playerregistration_set.all().order_by('rank')[:2]
weight = 0
for player in top_two_players:
rank = player.rank if player.rank is not None else 0
weight += rank
return weight