Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add coach model #2504

Merged
merged 2 commits into from
Oct 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions tabbycat/participants/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
from .emoji import pick_unused_emoji, populate_code_names_from_emoji, set_emoji
from .models import (
Adjudicator,
Coach,
Institution,
Region,
Speaker,
Expand Down Expand Up @@ -65,11 +66,27 @@ class TournamentInstitutionAdmin(ModelAdmin):
)
search_fields = ('institution__name', 'tournament__name')

# ==============================================================================
# Coach
# ==============================================================================


@admin.register(Coach)
class CoachAdmin(ModelAdmin):
list_display = (
"name",
"tournament_institution",
"email",
"region",
)
ordering = ("name",)
search_fields = ('name', )

# ==============================================================================
# Speaker
# ==============================================================================


@admin.register(Speaker)
class SpeakerAdmin(ModelAdmin):
list_filter = ('team__tournament', 'team__institution')
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# Generated by Django 5.0.4 on 2024-09-27 18:57

import django.db.models.deletion
from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
('participants', '0024_tournamentinstitution'),
]

operations = [
migrations.CreateModel(
name='Coach',
fields=[
('person_ptr', models.OneToOneField(auto_created=True, on_delete=django.db.models.deletion.CASCADE, parent_link=True, primary_key=True, serialize=False, to='participants.person')),
('tournament_institution', models.ForeignKey(blank=True, on_delete=django.db.models.deletion.CASCADE, to='participants.tournamentinstitution', verbose_name='tournament institution')),
],
options={
'verbose_name': 'coach',
'verbose_name_plural': 'coaches',
},
bases=('participants.person',),
),
]
23 changes: 23 additions & 0 deletions tabbycat/participants/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,29 @@ def get_public_name(self, tournament):
return self.code_name


class Coach(Person):
tournament_institution = models.ForeignKey(
TournamentInstitution,
models.CASCADE,
blank=True,
verbose_name=_("tournament institution"),
)

class Meta:
verbose_name = _("coach")
verbose_name_plural = _("coaches")

def __str__(self):
if self.institution is None:
return self.name
else:
return "%s (%s)" % (self.name, self.institution.code)

@property
def region(self):
return self.institution.region if self.institution else None


class TeamManager(LookupByNameFieldsMixin, models.Manager):
name_fields = ['short_name', 'long_name']

Expand Down
Loading