refactor: move role and specialty ownership to player

This commit is contained in:
2026-04-06 19:26:07 +02:00
parent aecbb62376
commit e6390fe664
4 changed files with 96 additions and 24 deletions

View File

@ -26,6 +26,13 @@ class Specialty(models.Model):
class Player(models.Model):
class Position(models.TextChoices):
PG = "PG", "PG"
SG = "SG", "SG"
SF = "SF", "SF"
PF = "PF", "PF"
C = "C", "C"
full_name = models.CharField(max_length=255)
first_name = models.CharField(max_length=100, blank=True)
last_name = models.CharField(max_length=100, blank=True)
@ -34,6 +41,9 @@ class Player(models.Model):
height_cm = models.DecimalField(max_digits=5, decimal_places=2, null=True, blank=True)
weight_kg = models.DecimalField(max_digits=5, decimal_places=2, null=True, blank=True)
wingspan_cm = models.DecimalField(max_digits=5, decimal_places=2, null=True, blank=True)
position = models.CharField(max_length=2, choices=Position.choices)
roles = models.ManyToManyField(Role, blank=True, related_name="players")
specialties = models.ManyToManyField(Specialty, blank=True, related_name="players")
created_at = models.DateTimeField(auto_now_add=True)
updated_at = models.DateTimeField(auto_now=True)
@ -60,20 +70,15 @@ class Competition(models.Model):
class Team(models.Model):
name = models.CharField(max_length=150)
competition = models.ForeignKey(
Competition,
on_delete=models.SET_NULL,
null=True,
blank=True,
related_name="teams",
)
country = models.CharField(max_length=100, blank=True)
created_at = models.DateTimeField(auto_now_add=True)
updated_at = models.DateTimeField(auto_now=True)
class Meta:
ordering = ["name"]
unique_together = ("name", "competition")
constraints = [
models.UniqueConstraint(fields=["name", "country"], name="uniq_team_name_country"),
]
def __str__(self) -> str:
return self.name
@ -94,13 +99,6 @@ class Season(models.Model):
class PlayerSeason(models.Model):
class Position(models.TextChoices):
PG = "PG", "PG"
SG = "SG", "SG"
SF = "SF", "SF"
PF = "PF", "PF"
C = "C", "C"
player = models.ForeignKey(Player, on_delete=models.CASCADE, related_name="player_seasons")
season = models.ForeignKey(Season, on_delete=models.CASCADE, related_name="player_seasons")
team = models.ForeignKey(
@ -117,14 +115,14 @@ class PlayerSeason(models.Model):
blank=True,
related_name="player_seasons",
)
position = models.CharField(max_length=2, choices=Position.choices)
roles = models.ManyToManyField(Role, blank=True, related_name="player_seasons")
specialties = models.ManyToManyField(Specialty, blank=True, related_name="player_seasons")
created_at = models.DateTimeField(auto_now_add=True)
updated_at = models.DateTimeField(auto_now=True)
class Meta:
ordering = ["player__full_name", "-season__start_year"]
constraints = [
models.UniqueConstraint(fields=["player", "season"], name="uniq_player_season"),
]
def __str__(self) -> str:
return f"{self.player.full_name} - {self.season.name}"