Merge branch 'feature/phase-2-playerseason-context-fix' into develop

This commit is contained in:
2026-04-06 19:30:58 +02:00
2 changed files with 29 additions and 2 deletions

View File

@ -0,0 +1,21 @@
# Generated by Django 5.2.2 on 2026-04-06 17:30
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('scouting', '0003_alter_player_position'),
]
operations = [
migrations.RemoveConstraint(
model_name='playerseason',
name='uniq_player_season',
),
migrations.AddConstraint(
model_name='playerseason',
constraint=models.UniqueConstraint(fields=('player', 'season', 'team', 'competition'), name='uniq_player_season_context', nulls_distinct=False),
),
]

View File

@ -121,11 +121,17 @@ class PlayerSeason(models.Model):
class Meta:
ordering = ["player__full_name", "-season__start_year"]
constraints = [
models.UniqueConstraint(fields=["player", "season"], name="uniq_player_season"),
models.UniqueConstraint(
fields=["player", "season", "team", "competition"],
name="uniq_player_season_context",
nulls_distinct=False,
),
]
def __str__(self) -> str:
return f"{self.player.full_name} - {self.season.name}"
team_name = self.team.name if self.team else "No team"
competition_name = self.competition.name if self.competition else "No competition"
return f"{self.player.full_name} - {self.season.name} - {team_name} - {competition_name}"
class PlayerSeasonStats(models.Model):