fix(v2-import): namespace source identity for snapshot upserts
This commit is contained in:
@ -5,9 +5,9 @@ from .models import Competition, Season, TeamSeason
|
||||
|
||||
@admin.register(Competition)
|
||||
class CompetitionAdmin(admin.ModelAdmin):
|
||||
list_display = ("name", "source_uid", "competition_type", "gender", "country", "is_active")
|
||||
list_display = ("name", "source_name", "source_uid", "competition_type", "gender", "country", "is_active")
|
||||
list_filter = ("competition_type", "gender", "country", "is_active")
|
||||
search_fields = ("name", "slug", "source_uid")
|
||||
search_fields = ("name", "slug", "source_name", "source_uid")
|
||||
|
||||
|
||||
@admin.register(Season)
|
||||
|
||||
@ -0,0 +1,35 @@
|
||||
# Generated by Django 5.2.12 on 2026-03-13 15:08
|
||||
|
||||
from django.db import migrations, models
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
("competitions", "0003_competition_source_uid_season_source_uid_and_more"),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.AddField(
|
||||
model_name="competition",
|
||||
name="source_name",
|
||||
field=models.CharField(blank=True, default="", max_length=120),
|
||||
),
|
||||
migrations.AlterField(
|
||||
model_name="competition",
|
||||
name="source_uid",
|
||||
field=models.CharField(blank=True, max_length=120, null=True),
|
||||
),
|
||||
migrations.AddConstraint(
|
||||
model_name="competition",
|
||||
constraint=models.UniqueConstraint(
|
||||
condition=models.Q(source_uid__isnull=False) & ~models.Q(source_uid=""),
|
||||
fields=("source_name", "source_uid"),
|
||||
name="uq_competition_source_namespace_uid",
|
||||
),
|
||||
),
|
||||
migrations.AddIndex(
|
||||
model_name="competition",
|
||||
index=models.Index(fields=["source_name", "source_uid"], name="competition_source__4c5f3d_idx"),
|
||||
),
|
||||
]
|
||||
@ -14,7 +14,8 @@ class Competition(models.Model):
|
||||
|
||||
name = models.CharField(max_length=220)
|
||||
slug = models.SlugField(max_length=240, unique=True)
|
||||
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)
|
||||
competition_type = models.CharField(max_length=24, choices=CompetitionType.choices)
|
||||
gender = models.CharField(max_length=16, choices=Gender.choices, default=Gender.MEN)
|
||||
level = models.PositiveSmallIntegerField(default=1)
|
||||
@ -32,10 +33,16 @@ class Competition(models.Model):
|
||||
class Meta:
|
||||
ordering = ["name"]
|
||||
constraints = [
|
||||
models.UniqueConstraint(fields=["name", "country"], name="uq_competition_name_country")
|
||||
models.UniqueConstraint(fields=["name", "country"], name="uq_competition_name_country"),
|
||||
models.UniqueConstraint(
|
||||
fields=["source_name", "source_uid"],
|
||||
condition=models.Q(source_uid__isnull=False) & ~models.Q(source_uid=""),
|
||||
name="uq_competition_source_namespace_uid",
|
||||
),
|
||||
]
|
||||
indexes = [
|
||||
models.Index(fields=["name"]),
|
||||
models.Index(fields=["source_name", "source_uid"]),
|
||||
models.Index(fields=["source_uid"]),
|
||||
models.Index(fields=["country"]),
|
||||
models.Index(fields=["competition_type"]),
|
||||
|
||||
Reference in New Issue
Block a user