fix(v2-import): namespace source identity for snapshot upserts
This commit is contained in:
@ -37,6 +37,7 @@ class PlayerCareerEntryInline(admin.TabularInline):
|
||||
class PlayerAdmin(admin.ModelAdmin):
|
||||
list_display = (
|
||||
"full_name",
|
||||
"source_name",
|
||||
"source_uid",
|
||||
"birth_date",
|
||||
"nationality",
|
||||
@ -54,7 +55,7 @@ class PlayerAdmin(admin.ModelAdmin):
|
||||
"origin_competition",
|
||||
"origin_team",
|
||||
)
|
||||
search_fields = ("full_name", "first_name", "last_name", "source_uid")
|
||||
search_fields = ("full_name", "first_name", "last_name", "source_name", "source_uid")
|
||||
inlines = (PlayerAliasInline, PlayerCareerEntryInline)
|
||||
actions = ("recompute_origin_fields",)
|
||||
|
||||
|
||||
39
apps/players/migrations/0007_player_source_namespaced_uid.py
Normal file
39
apps/players/migrations/0007_player_source_namespaced_uid.py
Normal file
@ -0,0 +1,39 @@
|
||||
# Generated by Django 5.2.12 on 2026-03-13 15:08
|
||||
|
||||
from django.db import migrations, models
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
("players", "0006_player_source_uid_and_more"),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.AddField(
|
||||
model_name="player",
|
||||
name="source_name",
|
||||
field=models.CharField(blank=True, default="", max_length=120),
|
||||
),
|
||||
migrations.AlterField(
|
||||
model_name="player",
|
||||
name="source_uid",
|
||||
field=models.CharField(blank=True, max_length=120, null=True),
|
||||
),
|
||||
migrations.RemoveConstraint(
|
||||
model_name="player",
|
||||
name="uq_player_full_name_birth_date",
|
||||
),
|
||||
migrations.AddConstraint(
|
||||
model_name="player",
|
||||
constraint=models.UniqueConstraint(
|
||||
condition=models.Q(source_uid__isnull=False) & ~models.Q(source_uid=""),
|
||||
fields=("source_name", "source_uid"),
|
||||
name="uq_player_source_namespace_uid",
|
||||
),
|
||||
),
|
||||
migrations.AddIndex(
|
||||
model_name="player",
|
||||
index=models.Index(fields=["source_name", "source_uid"], name="players_pla_source__73848c_idx"),
|
||||
),
|
||||
]
|
||||
@ -58,7 +58,8 @@ class Player(TimeStampedModel):
|
||||
first_name = models.CharField(max_length=120)
|
||||
last_name = models.CharField(max_length=120)
|
||||
full_name = models.CharField(max_length=260)
|
||||
source_uid = models.CharField(max_length=120, blank=True, null=True, unique=True)
|
||||
source_name = models.CharField(max_length=120, blank=True, default="")
|
||||
source_uid = models.CharField(max_length=120, blank=True, null=True)
|
||||
birth_date = models.DateField(blank=True, null=True)
|
||||
nationality = models.ForeignKey(
|
||||
"players.Nationality",
|
||||
@ -109,12 +110,14 @@ class Player(TimeStampedModel):
|
||||
ordering = ["full_name", "id"]
|
||||
constraints = [
|
||||
models.UniqueConstraint(
|
||||
fields=["full_name", "birth_date"],
|
||||
name="uq_player_full_name_birth_date",
|
||||
fields=["source_name", "source_uid"],
|
||||
condition=models.Q(source_uid__isnull=False) & ~models.Q(source_uid=""),
|
||||
name="uq_player_source_namespace_uid",
|
||||
)
|
||||
]
|
||||
indexes = [
|
||||
models.Index(fields=["full_name"]),
|
||||
models.Index(fields=["source_name", "source_uid"]),
|
||||
models.Index(fields=["source_uid"]),
|
||||
models.Index(fields=["last_name", "first_name"]),
|
||||
models.Index(fields=["birth_date"]),
|
||||
|
||||
Reference in New Issue
Block a user