diff --git a/app/scouting/migrations/0004_remove_playerseason_uniq_player_season_and_more.py b/app/scouting/migrations/0004_remove_playerseason_uniq_player_season_and_more.py new file mode 100644 index 0000000..440ef18 --- /dev/null +++ b/app/scouting/migrations/0004_remove_playerseason_uniq_player_season_and_more.py @@ -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), + ), + ] diff --git a/app/scouting/models.py b/app/scouting/models.py index ab35f96..1a7334d 100644 --- a/app/scouting/models.py +++ b/app/scouting/models.py @@ -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):