-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* add base models * Add User model * Add fields to Player * Add health_card model to player. Add coach. Need further constraints and representations. * Remove all redundant models, leave only players and teams. * Fix models and make base admin view * Fix imports
- Loading branch information
1 parent
9e90988
commit 50b47c4
Showing
8 changed files
with
640 additions
and
49 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,104 @@ | ||
from django.contrib import admin # noqa | ||
from django.contrib import admin | ||
from main.models import ( | ||
Anamnesis, | ||
Discipline, | ||
Health, | ||
Location, | ||
Player, | ||
Position, | ||
RespiratoryFailure, | ||
Role, | ||
Team, | ||
) | ||
|
||
# Register your models here. | ||
|
||
class TeamInline(admin.TabularInline): | ||
model = Team.players.through | ||
extra = 0 | ||
verbose_name = 'Команда' | ||
verbose_name_plural = 'Команды' | ||
autocomplete_fields = ['team'] | ||
|
||
|
||
class HealthInline(admin.TabularInline): | ||
model = Health | ||
extra = 0 | ||
verbose_name = 'Медицинская карта' | ||
verbose_name_plural = 'Медицинская карта' | ||
|
||
|
||
class PlayerInline(admin.TabularInline): | ||
model = Player.team.through | ||
extra = 0 | ||
verbose_name = 'Игрок' | ||
verbose_name_plural = 'Игроки' | ||
autocomplete_fields = ['player'] | ||
|
||
|
||
@admin.register(Player) | ||
class PlayerAdmin(admin.ModelAdmin): | ||
inlines = [TeamInline, HealthInline] | ||
fields = ['name', 'surname', 'patronymic', 'birth_date'] | ||
list_display = ['name', 'surname'] | ||
search_fields = ['surname', 'name'] | ||
|
||
|
||
@admin.register(Anamnesis) | ||
class AnamnesisAdmin(admin.ModelAdmin): | ||
search_fields = ['name'] | ||
|
||
def get_model_perms(self, request): | ||
"""Прячем из меню админки данную модель""" | ||
return {} | ||
|
||
|
||
@admin.register(Discipline) | ||
class DisciplineAdmin(admin.ModelAdmin): | ||
search_fields = ['name'] | ||
|
||
def get_model_perms(self, request): | ||
"""Прячем из меню админки данную модель""" | ||
return {} | ||
|
||
|
||
@admin.register(Team) | ||
class TeamAdmin(admin.ModelAdmin): | ||
search_fields = ['name'] | ||
autocomplete_fields = ['location', 'discipline'] | ||
inlines = [PlayerInline] | ||
|
||
|
||
@admin.register(Location) | ||
class LocationAdmin(admin.ModelAdmin): | ||
search_fields = ['name'] | ||
|
||
def get_model_perms(self, request): | ||
"""Прячем из меню админки данную модель""" | ||
return {} | ||
|
||
|
||
@admin.register(Position) | ||
class PositionAdmin(admin.ModelAdmin): | ||
search_fields = ['name'] | ||
|
||
def get_model_perms(self, request): | ||
"""Прячем из меню админки данную модель""" | ||
return {} | ||
|
||
|
||
@admin.register(Role) | ||
class RoleAdmin(admin.ModelAdmin): | ||
search_fields = ['name'] | ||
|
||
def get_model_perms(self, request): | ||
"""Прячем из меню админки данную модель""" | ||
return {} | ||
|
||
|
||
@admin.register(RespiratoryFailure) | ||
class RespiratoryFailureAdmin(admin.ModelAdmin): | ||
search_fields = ['name'] | ||
|
||
def get_model_perms(self, request): | ||
"""Прячем из меню админки данную модель""" | ||
return {} |
161 changes: 161 additions & 0 deletions
161
adaptive_hockey_federation/main/migrations/0001_initial.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,161 @@ | ||
# Generated by Django 4.2.6 on 2023-11-25 14:50 | ||
|
||
from django.db import migrations, models | ||
import django.db.models.deletion | ||
|
||
|
||
class Migration(migrations.Migration): | ||
|
||
initial = True | ||
|
||
dependencies = [ | ||
] | ||
|
||
operations = [ | ||
migrations.CreateModel( | ||
name='Anamnesis', | ||
fields=[ | ||
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), | ||
('name', models.CharField(max_length=256, unique=True, verbose_name='Название')), | ||
], | ||
options={ | ||
'verbose_name': 'Диагноз', | ||
'verbose_name_plural': 'Диагнозы', | ||
'ordering': ('name',), | ||
'abstract': False, | ||
}, | ||
), | ||
migrations.CreateModel( | ||
name='Discipline', | ||
fields=[ | ||
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), | ||
('name', models.CharField(max_length=256, unique=True, verbose_name='Название')), | ||
], | ||
options={ | ||
'verbose_name': 'Дисциплина', | ||
'verbose_name_plural': 'Дисциплины', | ||
'ordering': ('name',), | ||
'abstract': False, | ||
}, | ||
), | ||
migrations.CreateModel( | ||
name='Location', | ||
fields=[ | ||
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), | ||
('name', models.CharField(max_length=256, unique=True, verbose_name='Название')), | ||
], | ||
options={ | ||
'verbose_name': 'Территория', | ||
'verbose_name_plural': 'Территории', | ||
'ordering': ('name',), | ||
'abstract': False, | ||
}, | ||
), | ||
migrations.CreateModel( | ||
name='Player', | ||
fields=[ | ||
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), | ||
('name', models.CharField(max_length=256, verbose_name='Имя')), | ||
('surname', models.CharField(max_length=256, verbose_name='Фамилия')), | ||
('patronymic', models.CharField(blank=True, max_length=256, null=True, verbose_name='Отчество')), | ||
('birth_date', models.DateField()), | ||
('sex', models.CharField(blank=True, choices=[('male', 'Мужской'), ('female', 'Женский')], max_length=6, null=True, verbose_name='Пол')), | ||
], | ||
options={ | ||
'verbose_name': 'Игрок', | ||
'verbose_name_plural': 'Игроки', | ||
'ordering': ('surname', 'name', 'patronymic'), | ||
'abstract': False, | ||
'default_related_name': 'players', | ||
}, | ||
), | ||
migrations.CreateModel( | ||
name='Position', | ||
fields=[ | ||
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), | ||
('name', models.CharField(max_length=256, unique=True, verbose_name='Название')), | ||
], | ||
options={ | ||
'verbose_name': 'Игровая позиция', | ||
'verbose_name_plural': 'Игровые позиции', | ||
'ordering': ('name',), | ||
'abstract': False, | ||
}, | ||
), | ||
migrations.CreateModel( | ||
name='RespiratoryFailure', | ||
fields=[ | ||
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), | ||
('name', models.CharField(max_length=256, unique=True, verbose_name='Название')), | ||
], | ||
options={ | ||
'verbose_name': 'Класс ХДН', | ||
'verbose_name_plural': 'Классы ХДН', | ||
'ordering': ('name',), | ||
'abstract': False, | ||
}, | ||
), | ||
migrations.CreateModel( | ||
name='Role', | ||
fields=[ | ||
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), | ||
('name', models.CharField(max_length=256, unique=True, verbose_name='Название')), | ||
], | ||
options={ | ||
'verbose_name': 'Игровая позиция', | ||
'verbose_name_plural': 'Игровые позиции', | ||
'ordering': ('name',), | ||
'abstract': False, | ||
}, | ||
), | ||
migrations.CreateModel( | ||
name='Team', | ||
fields=[ | ||
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), | ||
('name', models.CharField(max_length=256)), | ||
('discipline', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.SET_NULL, to='main.discipline', verbose_name='Дисциплина команды')), | ||
('location', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.SET_NULL, to='main.location', verbose_name='Локация команды')), | ||
], | ||
options={ | ||
'verbose_name': 'Команда', | ||
'verbose_name_plural': 'Команды', | ||
'default_related_name': 'teams', | ||
}, | ||
), | ||
migrations.CreateModel( | ||
name='PlayerTeam', | ||
fields=[ | ||
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), | ||
('number', models.CharField(max_length=256, verbose_name='Игровой номер')), | ||
('player', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='player_teams', to='main.player', verbose_name='Игрок')), | ||
('position', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.SET_NULL, to='main.position', verbose_name='Позиция игрока')), | ||
('role', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.SET_NULL, to='main.role', verbose_name='Статус игрока')), | ||
('team', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='team_players', to='main.team', verbose_name='Команда')), | ||
], | ||
), | ||
migrations.AddField( | ||
model_name='player', | ||
name='team', | ||
field=models.ManyToManyField(through='main.PlayerTeam', to='main.team', verbose_name='Команда'), | ||
), | ||
migrations.CreateModel( | ||
name='Health', | ||
fields=[ | ||
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), | ||
('is_permanent', models.BooleanField(default=False, verbose_name='Класс ХДН подтверждён перманентно')), | ||
('revision', models.CharField(blank=True, max_length=256, null=True, verbose_name='Пересмотр класса ХДН')), | ||
('wheelchair', models.BooleanField(default=False, verbose_name='На коляске')), | ||
('anamnesis', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.SET_NULL, to='main.anamnesis', verbose_name='Диагноз')), | ||
('player', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='health', to='main.player', verbose_name='Игрок')), | ||
('respiratory_failure', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='respiratory_failure_players', to='main.respiratoryfailure', verbose_name='Класс ХДН')), | ||
], | ||
), | ||
migrations.AddConstraint( | ||
model_name='team', | ||
constraint=models.UniqueConstraint(fields=('name', 'location', 'discipline'), name='team_location_unique'), | ||
), | ||
migrations.AddConstraint( | ||
model_name='player', | ||
constraint=models.UniqueConstraint(fields=('name', 'surname', 'patronymic', 'birth_date'), name='player_unique'), | ||
), | ||
] |
Oops, something went wrong.