phase3: add normalized domain schema, admin, services, and multistage docker build
This commit is contained in:
24
apps/competitions/admin.py
Normal file
24
apps/competitions/admin.py
Normal file
@ -0,0 +1,24 @@
|
||||
from django.contrib import admin
|
||||
|
||||
from .models import Competition, Season, TeamSeason
|
||||
|
||||
|
||||
@admin.register(Competition)
|
||||
class CompetitionAdmin(admin.ModelAdmin):
|
||||
list_display = ("name", "competition_type", "gender", "country", "is_active")
|
||||
list_filter = ("competition_type", "gender", "country", "is_active")
|
||||
search_fields = ("name", "slug")
|
||||
|
||||
|
||||
@admin.register(Season)
|
||||
class SeasonAdmin(admin.ModelAdmin):
|
||||
list_display = ("label", "start_date", "end_date", "is_current")
|
||||
list_filter = ("is_current",)
|
||||
search_fields = ("label",)
|
||||
|
||||
|
||||
@admin.register(TeamSeason)
|
||||
class TeamSeasonAdmin(admin.ModelAdmin):
|
||||
list_display = ("team", "season", "competition", "standing", "wins", "losses")
|
||||
list_filter = ("season", "competition")
|
||||
search_fields = ("team__name", "competition__name", "season__label")
|
||||
58
apps/competitions/migrations/0001_initial.py
Normal file
58
apps/competitions/migrations/0001_initial.py
Normal file
@ -0,0 +1,58 @@
|
||||
# Generated by Django 5.2.12 on 2026-03-10 09:33
|
||||
|
||||
from django.db import migrations, models
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
initial = True
|
||||
|
||||
dependencies = [
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.CreateModel(
|
||||
name='Competition',
|
||||
fields=[
|
||||
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
|
||||
('name', models.CharField(max_length=220)),
|
||||
('slug', models.SlugField(max_length=240, unique=True)),
|
||||
('competition_type', models.CharField(choices=[('league', 'League'), ('cup', 'Cup'), ('international', 'International')], max_length=24)),
|
||||
('gender', models.CharField(choices=[('men', 'Men'), ('women', 'Women'), ('mixed', 'Mixed')], default='men', max_length=16)),
|
||||
('level', models.PositiveSmallIntegerField(default=1)),
|
||||
('is_active', models.BooleanField(default=True)),
|
||||
('created_at', models.DateTimeField(auto_now_add=True)),
|
||||
('updated_at', models.DateTimeField(auto_now=True)),
|
||||
],
|
||||
options={
|
||||
'ordering': ['name'],
|
||||
},
|
||||
),
|
||||
migrations.CreateModel(
|
||||
name='Season',
|
||||
fields=[
|
||||
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
|
||||
('label', models.CharField(max_length=40, unique=True)),
|
||||
('start_date', models.DateField()),
|
||||
('end_date', models.DateField()),
|
||||
('is_current', models.BooleanField(default=False)),
|
||||
],
|
||||
options={
|
||||
'ordering': ['-start_date'],
|
||||
},
|
||||
),
|
||||
migrations.CreateModel(
|
||||
name='TeamSeason',
|
||||
fields=[
|
||||
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
|
||||
('standing', models.PositiveSmallIntegerField(blank=True, null=True)),
|
||||
('wins', models.PositiveSmallIntegerField(blank=True, null=True)),
|
||||
('losses', models.PositiveSmallIntegerField(blank=True, null=True)),
|
||||
('points', models.PositiveSmallIntegerField(blank=True, null=True)),
|
||||
('coach_name', models.CharField(blank=True, max_length=140)),
|
||||
],
|
||||
options={
|
||||
'ordering': ['competition', 'season', 'team'],
|
||||
},
|
||||
),
|
||||
]
|
||||
94
apps/competitions/migrations/0002_initial.py
Normal file
94
apps/competitions/migrations/0002_initial.py
Normal file
@ -0,0 +1,94 @@
|
||||
# Generated by Django 5.2.12 on 2026-03-10 09:33
|
||||
|
||||
import django.db.models.deletion
|
||||
from django.db import migrations, models
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
initial = True
|
||||
|
||||
dependencies = [
|
||||
('competitions', '0001_initial'),
|
||||
('players', '0001_initial'),
|
||||
('teams', '0001_initial'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.AddField(
|
||||
model_name='competition',
|
||||
name='country',
|
||||
field=models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='competitions', to='players.nationality'),
|
||||
),
|
||||
migrations.AddIndex(
|
||||
model_name='season',
|
||||
index=models.Index(fields=['is_current'], name='competition_is_curr_787938_idx'),
|
||||
),
|
||||
migrations.AddIndex(
|
||||
model_name='season',
|
||||
index=models.Index(fields=['start_date'], name='competition_start_d_08fb82_idx'),
|
||||
),
|
||||
migrations.AddIndex(
|
||||
model_name='season',
|
||||
index=models.Index(fields=['end_date'], name='competition_end_dat_4ed2e7_idx'),
|
||||
),
|
||||
migrations.AddConstraint(
|
||||
model_name='season',
|
||||
constraint=models.CheckConstraint(condition=models.Q(('end_date__gte', models.F('start_date'))), name='ck_season_dates'),
|
||||
),
|
||||
migrations.AddField(
|
||||
model_name='teamseason',
|
||||
name='competition',
|
||||
field=models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='team_seasons', to='competitions.competition'),
|
||||
),
|
||||
migrations.AddField(
|
||||
model_name='teamseason',
|
||||
name='season',
|
||||
field=models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='team_seasons', to='competitions.season'),
|
||||
),
|
||||
migrations.AddField(
|
||||
model_name='teamseason',
|
||||
name='team',
|
||||
field=models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='team_seasons', to='teams.team'),
|
||||
),
|
||||
migrations.AddIndex(
|
||||
model_name='competition',
|
||||
index=models.Index(fields=['name'], name='competition_name_57eea2_idx'),
|
||||
),
|
||||
migrations.AddIndex(
|
||||
model_name='competition',
|
||||
index=models.Index(fields=['country'], name='competition_country_93a128_idx'),
|
||||
),
|
||||
migrations.AddIndex(
|
||||
model_name='competition',
|
||||
index=models.Index(fields=['competition_type'], name='competition_competi_7f1bff_idx'),
|
||||
),
|
||||
migrations.AddIndex(
|
||||
model_name='competition',
|
||||
index=models.Index(fields=['gender'], name='competition_gender_e21a65_idx'),
|
||||
),
|
||||
migrations.AddIndex(
|
||||
model_name='competition',
|
||||
index=models.Index(fields=['is_active'], name='competition_is_acti_53f00f_idx'),
|
||||
),
|
||||
migrations.AddConstraint(
|
||||
model_name='competition',
|
||||
constraint=models.UniqueConstraint(fields=('name', 'country'), name='uq_competition_name_country'),
|
||||
),
|
||||
migrations.AddIndex(
|
||||
model_name='teamseason',
|
||||
index=models.Index(fields=['team', 'season'], name='competition_team_id_c656bd_idx'),
|
||||
),
|
||||
migrations.AddIndex(
|
||||
model_name='teamseason',
|
||||
index=models.Index(fields=['season', 'competition'], name='competition_season__9f17b6_idx'),
|
||||
),
|
||||
migrations.AddIndex(
|
||||
model_name='teamseason',
|
||||
index=models.Index(fields=['competition', 'standing'], name='competition_competi_e1c8c7_idx'),
|
||||
),
|
||||
migrations.AddConstraint(
|
||||
model_name='teamseason',
|
||||
constraint=models.UniqueConstraint(fields=('team', 'season', 'competition'), name='uq_team_season_competition'),
|
||||
),
|
||||
]
|
||||
98
apps/competitions/models.py
Normal file
98
apps/competitions/models.py
Normal file
@ -0,0 +1,98 @@
|
||||
from django.db import models
|
||||
|
||||
|
||||
class Competition(models.Model):
|
||||
class CompetitionType(models.TextChoices):
|
||||
LEAGUE = "league", "League"
|
||||
CUP = "cup", "Cup"
|
||||
INTERNATIONAL = "international", "International"
|
||||
|
||||
class Gender(models.TextChoices):
|
||||
MEN = "men", "Men"
|
||||
WOMEN = "women", "Women"
|
||||
MIXED = "mixed", "Mixed"
|
||||
|
||||
name = models.CharField(max_length=220)
|
||||
slug = models.SlugField(max_length=240, unique=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)
|
||||
country = models.ForeignKey(
|
||||
"players.Nationality",
|
||||
on_delete=models.SET_NULL,
|
||||
blank=True,
|
||||
null=True,
|
||||
related_name="competitions",
|
||||
)
|
||||
is_active = models.BooleanField(default=True)
|
||||
created_at = models.DateTimeField(auto_now_add=True)
|
||||
updated_at = models.DateTimeField(auto_now=True)
|
||||
|
||||
class Meta:
|
||||
ordering = ["name"]
|
||||
constraints = [
|
||||
models.UniqueConstraint(fields=["name", "country"], name="uq_competition_name_country")
|
||||
]
|
||||
indexes = [
|
||||
models.Index(fields=["name"]),
|
||||
models.Index(fields=["country"]),
|
||||
models.Index(fields=["competition_type"]),
|
||||
models.Index(fields=["gender"]),
|
||||
models.Index(fields=["is_active"]),
|
||||
]
|
||||
|
||||
def __str__(self) -> str:
|
||||
return self.name
|
||||
|
||||
|
||||
class Season(models.Model):
|
||||
label = models.CharField(max_length=40, unique=True)
|
||||
start_date = models.DateField()
|
||||
end_date = models.DateField()
|
||||
is_current = models.BooleanField(default=False)
|
||||
|
||||
class Meta:
|
||||
ordering = ["-start_date"]
|
||||
constraints = [
|
||||
models.CheckConstraint(check=models.Q(end_date__gte=models.F("start_date")), name="ck_season_dates")
|
||||
]
|
||||
indexes = [
|
||||
models.Index(fields=["is_current"]),
|
||||
models.Index(fields=["start_date"]),
|
||||
models.Index(fields=["end_date"]),
|
||||
]
|
||||
|
||||
def __str__(self) -> str:
|
||||
return self.label
|
||||
|
||||
|
||||
class TeamSeason(models.Model):
|
||||
team = models.ForeignKey("teams.Team", on_delete=models.CASCADE, related_name="team_seasons")
|
||||
season = models.ForeignKey("competitions.Season", on_delete=models.CASCADE, related_name="team_seasons")
|
||||
competition = models.ForeignKey(
|
||||
"competitions.Competition",
|
||||
on_delete=models.CASCADE,
|
||||
related_name="team_seasons",
|
||||
)
|
||||
standing = models.PositiveSmallIntegerField(blank=True, null=True)
|
||||
wins = models.PositiveSmallIntegerField(blank=True, null=True)
|
||||
losses = models.PositiveSmallIntegerField(blank=True, null=True)
|
||||
points = models.PositiveSmallIntegerField(blank=True, null=True)
|
||||
coach_name = models.CharField(max_length=140, blank=True)
|
||||
|
||||
class Meta:
|
||||
ordering = ["competition", "season", "team"]
|
||||
constraints = [
|
||||
models.UniqueConstraint(
|
||||
fields=["team", "season", "competition"],
|
||||
name="uq_team_season_competition",
|
||||
)
|
||||
]
|
||||
indexes = [
|
||||
models.Index(fields=["team", "season"]),
|
||||
models.Index(fields=["season", "competition"]),
|
||||
models.Index(fields=["competition", "standing"]),
|
||||
]
|
||||
|
||||
def __str__(self) -> str:
|
||||
return f"{self.team} - {self.season} - {self.competition}"
|
||||
Reference in New Issue
Block a user