Improve Django-admin interface, inlines and filters
Signed-off-by: Emmy D'Anello <emmy.danello@animath.fr>
This commit is contained in:
parent
cae1c6fdb8
commit
de504398d2
|
@ -7,11 +7,34 @@ from django.utils.translation import gettext_lazy as _
|
||||||
from .models import Draw, Pool, Round, TeamDraw
|
from .models import Draw, Pool, Round, TeamDraw
|
||||||
|
|
||||||
|
|
||||||
|
class RoundInline(admin.TabularInline):
|
||||||
|
model = Round
|
||||||
|
extra = 0
|
||||||
|
autocomplete_fields = ('draw', 'current_pool',)
|
||||||
|
show_change_link = True
|
||||||
|
|
||||||
|
|
||||||
|
class PoolInline(admin.TabularInline):
|
||||||
|
model = Pool
|
||||||
|
extra = 0
|
||||||
|
autocomplete_fields = ('round', 'current_team', 'associated_pool',)
|
||||||
|
show_change_link = True
|
||||||
|
|
||||||
|
|
||||||
|
class TeamDrawInline(admin.TabularInline):
|
||||||
|
model = TeamDraw
|
||||||
|
extra = 0
|
||||||
|
autocomplete_fields = ('participation', 'round', 'pool',)
|
||||||
|
show_change_link = True
|
||||||
|
|
||||||
|
|
||||||
@admin.register(Draw)
|
@admin.register(Draw)
|
||||||
class DrawAdmin(admin.ModelAdmin):
|
class DrawAdmin(admin.ModelAdmin):
|
||||||
list_display = ('tournament', 'teams', 'current_round', 'get_state',)
|
list_display = ('tournament', 'teams', 'current_round', 'get_state',)
|
||||||
list_filter = ('tournament', 'current_round',)
|
list_filter = ('tournament', 'current_round__number',)
|
||||||
search_fields = ('tournament__name', 'tournament__participation__team__trigram',)
|
search_fields = ('tournament__name', 'tournament__participation__team__trigram',)
|
||||||
|
autocomplete_fields = ('tournament',)
|
||||||
|
inlines = (RoundInline,)
|
||||||
|
|
||||||
@admin.display(description=_("teams"))
|
@admin.display(description=_("teams"))
|
||||||
def teams(self, record: Draw):
|
def teams(self, record: Draw):
|
||||||
|
@ -20,10 +43,16 @@ class DrawAdmin(admin.ModelAdmin):
|
||||||
|
|
||||||
@admin.register(Round)
|
@admin.register(Round)
|
||||||
class RoundAdmin(admin.ModelAdmin):
|
class RoundAdmin(admin.ModelAdmin):
|
||||||
list_display = ('draw', 'number', 'teams',)
|
list_display = ('draw', 'tournament', 'number', 'teams',)
|
||||||
list_filter = ('draw__tournament', 'number',)
|
list_filter = ('draw__tournament', 'number',)
|
||||||
search_fields = ('draw__tournament__name', 'pool__teamdraw__participation__team__trigram')
|
search_fields = ('draw__tournament__name', 'pool__teamdraw__participation__team__trigram')
|
||||||
ordering = ('draw__tournament__name', 'number')
|
ordering = ('draw__tournament__name', 'number')
|
||||||
|
autocomplete_fields = ('draw', 'current_pool',)
|
||||||
|
inlines = (PoolInline,)
|
||||||
|
|
||||||
|
@admin.display(description=_("tournament"), ordering='draw__tournament__name')
|
||||||
|
def tournament(self, record):
|
||||||
|
return record.draw.tournament
|
||||||
|
|
||||||
@admin.display(description=_("teams"))
|
@admin.display(description=_("teams"))
|
||||||
def teams(self, record: Round):
|
def teams(self, record: Round):
|
||||||
|
@ -36,6 +65,8 @@ class PoolAdmin(admin.ModelAdmin):
|
||||||
list_filter = ('round__draw__tournament', 'round__number', 'letter')
|
list_filter = ('round__draw__tournament', 'round__number', 'letter')
|
||||||
ordering = ('round__draw__tournament__name', 'round', 'letter')
|
ordering = ('round__draw__tournament__name', 'round', 'letter')
|
||||||
search_fields = ('round__draw__tournament__name', 'teamdraw__participation__team__trigram',)
|
search_fields = ('round__draw__tournament__name', 'teamdraw__participation__team__trigram',)
|
||||||
|
autocomplete_fields = ('round', 'current_team', 'associated_pool',)
|
||||||
|
inlines = (TeamDrawInline,)
|
||||||
|
|
||||||
@admin.display(ordering='round__draw__tournament__name', description=_("tournament"))
|
@admin.display(ordering='round__draw__tournament__name', description=_("tournament"))
|
||||||
def tournament(self, record):
|
def tournament(self, record):
|
||||||
|
@ -52,6 +83,7 @@ class TeamDrawAdmin(admin.ModelAdmin):
|
||||||
'passage_index', 'choose_index', 'passage_dice', 'choice_dice',)
|
'passage_index', 'choose_index', 'passage_dice', 'choice_dice',)
|
||||||
list_filter = ('round__draw__tournament', 'round__number', 'pool__letter',)
|
list_filter = ('round__draw__tournament', 'round__number', 'pool__letter',)
|
||||||
search_fields = ('round__draw__tournament__name', 'participation__team__trigram',)
|
search_fields = ('round__draw__tournament__name', 'participation__team__trigram',)
|
||||||
|
autocomplete_fields = ('participation', 'round', 'pool',)
|
||||||
|
|
||||||
@admin.display(ordering='round__draw__tournament__name', description=_("tournament"))
|
@admin.display(ordering='round__draw__tournament__name', description=_("tournament"))
|
||||||
def tournament(self, record):
|
def tournament(self, record):
|
||||||
|
|
|
@ -89,6 +89,7 @@ class Draw(models.Model):
|
||||||
return 'WAITING_DRAW_PROBLEM'
|
return 'WAITING_DRAW_PROBLEM'
|
||||||
else:
|
else:
|
||||||
return 'WAITING_CHOOSE_PROBLEM'
|
return 'WAITING_CHOOSE_PROBLEM'
|
||||||
|
get_state.short_description = _('State')
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def information(self):
|
def information(self):
|
||||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -7,11 +7,74 @@ from django.utils.translation import gettext_lazy as _
|
||||||
from .models import Note, Participation, Passage, Pool, Solution, Synthesis, Team, Tournament, Tweak
|
from .models import Note, Participation, Passage, Pool, Solution, Synthesis, Team, Tournament, Tweak
|
||||||
|
|
||||||
|
|
||||||
|
class ParticipationInline(admin.StackedInline):
|
||||||
|
model = Participation
|
||||||
|
extra = 0
|
||||||
|
autocomplete_fields = ('team', 'tournament',)
|
||||||
|
show_change_link = True
|
||||||
|
|
||||||
|
|
||||||
|
class ParticipationTabularInline(admin.TabularInline):
|
||||||
|
model = Participation
|
||||||
|
extra = 0
|
||||||
|
fields = ('team', 'valid', 'final',)
|
||||||
|
readonly_fields = ('team',)
|
||||||
|
ordering = ('final', 'valid', 'team__trigram',)
|
||||||
|
autocomplete_fields = ('tournament',)
|
||||||
|
show_change_link = True
|
||||||
|
|
||||||
|
|
||||||
|
class SolutionInline(admin.TabularInline):
|
||||||
|
model = Solution
|
||||||
|
extra = 0
|
||||||
|
ordering = ('problem',)
|
||||||
|
autocomplete_fields = ('participation',)
|
||||||
|
show_change_link = True
|
||||||
|
|
||||||
|
|
||||||
|
class SynthesisInline(admin.TabularInline):
|
||||||
|
model = Synthesis
|
||||||
|
extra = 0
|
||||||
|
ordering = ('passage__solution_number', 'type',)
|
||||||
|
autocomplete_fields = ('passage',)
|
||||||
|
show_change_link = True
|
||||||
|
|
||||||
|
|
||||||
|
class PoolInline(admin.TabularInline):
|
||||||
|
model = Pool
|
||||||
|
extra = 0
|
||||||
|
autocomplete_fields = ('tournament', 'participations', 'juries',)
|
||||||
|
show_change_link = True
|
||||||
|
|
||||||
|
|
||||||
|
class PassageInline(admin.TabularInline):
|
||||||
|
model = Passage
|
||||||
|
extra = 0
|
||||||
|
ordering = ('position',)
|
||||||
|
autocomplete_fields = ('defender', 'opponent', 'reporter', 'observer',)
|
||||||
|
show_change_link = True
|
||||||
|
|
||||||
|
|
||||||
|
class NoteInline(admin.TabularInline):
|
||||||
|
model = Note
|
||||||
|
extra = 0
|
||||||
|
autocomplete_fields = ('jury',)
|
||||||
|
show_change_link = True
|
||||||
|
|
||||||
|
|
||||||
|
class TweakInline(admin.TabularInline):
|
||||||
|
model = Tweak
|
||||||
|
extra = 0
|
||||||
|
autocomplete_fields = ('participation', 'pool',)
|
||||||
|
show_change_link = True
|
||||||
|
|
||||||
|
|
||||||
@admin.register(Team)
|
@admin.register(Team)
|
||||||
class TeamAdmin(admin.ModelAdmin):
|
class TeamAdmin(admin.ModelAdmin):
|
||||||
list_display = ('name', 'trigram', 'tournament', 'valid', 'final',)
|
list_display = ('name', 'trigram', 'tournament', 'valid', 'final',)
|
||||||
search_fields = ('name', 'trigram',)
|
search_fields = ('name', 'trigram',)
|
||||||
list_filter = ('participation__valid', 'participation__tournament', 'participation__final',)
|
list_filter = ('participation__valid', 'participation__tournament', 'participation__final',)
|
||||||
|
inlines = (ParticipationInline,)
|
||||||
|
|
||||||
@admin.display(description=_("tournament"))
|
@admin.display(description=_("tournament"))
|
||||||
def tournament(self, record):
|
def tournament(self, record):
|
||||||
|
@ -32,6 +95,7 @@ class ParticipationAdmin(admin.ModelAdmin):
|
||||||
search_fields = ('team__name', 'team__trigram',)
|
search_fields = ('team__name', 'team__trigram',)
|
||||||
list_filter = ('valid',)
|
list_filter = ('valid',)
|
||||||
autocomplete_fields = ('team', 'tournament',)
|
autocomplete_fields = ('team', 'tournament',)
|
||||||
|
inlines = (SolutionInline, SynthesisInline,)
|
||||||
|
|
||||||
|
|
||||||
@admin.register(Pool)
|
@admin.register(Pool)
|
||||||
|
@ -40,6 +104,7 @@ class PoolAdmin(admin.ModelAdmin):
|
||||||
list_filter = ('tournament', 'round', 'letter',)
|
list_filter = ('tournament', 'round', 'letter',)
|
||||||
search_fields = ('participations__team__name', 'participations__team__trigram',)
|
search_fields = ('participations__team__name', 'participations__team__trigram',)
|
||||||
autocomplete_fields = ('tournament', 'participations', 'juries',)
|
autocomplete_fields = ('tournament', 'participations', 'juries',)
|
||||||
|
inlines = (PassageInline, TweakInline,)
|
||||||
|
|
||||||
@admin.display(description=_("teams"))
|
@admin.display(description=_("teams"))
|
||||||
def teams(self, record: Pool):
|
def teams(self, record: Pool):
|
||||||
|
@ -49,28 +114,30 @@ class PoolAdmin(admin.ModelAdmin):
|
||||||
@admin.register(Passage)
|
@admin.register(Passage)
|
||||||
class PassageAdmin(admin.ModelAdmin):
|
class PassageAdmin(admin.ModelAdmin):
|
||||||
list_display = ('__str__', 'defender_trigram', 'solution_number', 'opponent_trigram', 'reporter_trigram',
|
list_display = ('__str__', 'defender_trigram', 'solution_number', 'opponent_trigram', 'reporter_trigram',
|
||||||
'pool_abbr', 'tournament')
|
'pool_abbr', 'position', 'tournament')
|
||||||
list_filter = ('pool__tournament', 'pool__round', 'pool__letter', 'solution_number',)
|
list_filter = ('pool__tournament', 'pool__round', 'pool__letter', 'solution_number',)
|
||||||
search_fields = ('pool__participations__team__name', 'pool__participations__team__trigram',)
|
search_fields = ('pool__participations__team__name', 'pool__participations__team__trigram',)
|
||||||
|
ordering = ('pool__tournament', 'pool__round', 'pool__letter', 'position',)
|
||||||
autocomplete_fields = ('pool', 'defender', 'opponent', 'reporter', 'observer',)
|
autocomplete_fields = ('pool', 'defender', 'opponent', 'reporter', 'observer',)
|
||||||
|
inlines = (NoteInline,)
|
||||||
|
|
||||||
@admin.display(description=_("defender"))
|
@admin.display(description=_("defender"), ordering='defender__team__trigram')
|
||||||
def defender_trigram(self, record: Passage):
|
def defender_trigram(self, record: Passage):
|
||||||
return record.defender.team.trigram
|
return record.defender.team.trigram
|
||||||
|
|
||||||
@admin.display(description=_("opponent"))
|
@admin.display(description=_("opponent"), ordering='opponent__team__trigram')
|
||||||
def opponent_trigram(self, record: Passage):
|
def opponent_trigram(self, record: Passage):
|
||||||
return record.opponent.team.trigram
|
return record.opponent.team.trigram
|
||||||
|
|
||||||
@admin.display(description=_("reporter"))
|
@admin.display(description=_("reporter"), ordering='reporter__team__trigram')
|
||||||
def reporter_trigram(self, record: Passage):
|
def reporter_trigram(self, record: Passage):
|
||||||
return record.reporter.team.trigram
|
return record.reporter.team.trigram
|
||||||
|
|
||||||
@admin.display(description=_("pool"))
|
@admin.display(description=_("pool"), ordering='pool__letter')
|
||||||
def pool_abbr(self, record):
|
def pool_abbr(self, record):
|
||||||
return f"{record.pool.get_letter_display()}{record.pool.round}"
|
return f"{record.pool.get_letter_display()}{record.pool.round}"
|
||||||
|
|
||||||
@admin.display(description=_("tournament"))
|
@admin.display(description=_("tournament"), ordering='pool__tournament__name')
|
||||||
def tournament(self, record: Passage):
|
def tournament(self, record: Passage):
|
||||||
return record.pool.tournament
|
return record.pool.tournament
|
||||||
|
|
||||||
|
@ -124,9 +191,11 @@ class SynthesisAdmin(admin.ModelAdmin):
|
||||||
|
|
||||||
@admin.register(Tournament)
|
@admin.register(Tournament)
|
||||||
class TournamentAdmin(admin.ModelAdmin):
|
class TournamentAdmin(admin.ModelAdmin):
|
||||||
list_display = ('name',)
|
list_display = ('name', 'date_start', 'date_end',)
|
||||||
search_fields = ('name',)
|
search_fields = ('name',)
|
||||||
|
ordering = ('date_start', 'name',)
|
||||||
autocomplete_fields = ('organizers',)
|
autocomplete_fields = ('organizers',)
|
||||||
|
inlines = (ParticipationTabularInline, PoolInline,)
|
||||||
|
|
||||||
|
|
||||||
@admin.register(Tweak)
|
@admin.register(Tweak)
|
||||||
|
|
|
@ -3,13 +3,45 @@
|
||||||
|
|
||||||
from django.contrib import admin
|
from django.contrib import admin
|
||||||
from django.contrib.admin import ModelAdmin
|
from django.contrib.admin import ModelAdmin
|
||||||
|
from django.contrib.auth.admin import UserAdmin
|
||||||
|
from django.contrib.auth.models import User
|
||||||
from django.utils.translation import gettext_lazy as _
|
from django.utils.translation import gettext_lazy as _
|
||||||
from polymorphic.admin import PolymorphicChildModelAdmin, PolymorphicChildModelFilter, PolymorphicParentModelAdmin
|
from polymorphic.admin import PolymorphicChildModelAdmin, PolymorphicChildModelFilter, PolymorphicParentModelAdmin, \
|
||||||
|
PolymorphicInlineSupportMixin, StackedPolymorphicInline
|
||||||
|
|
||||||
from .models import CoachRegistration, ParticipantRegistration, Payment, Registration, \
|
from .models import CoachRegistration, ParticipantRegistration, Payment, Registration, \
|
||||||
StudentRegistration, VolunteerRegistration
|
StudentRegistration, VolunteerRegistration
|
||||||
|
|
||||||
|
|
||||||
|
class RegistrationInline(StackedPolymorphicInline):
|
||||||
|
class StudentRegistrationInline(StackedPolymorphicInline.Child):
|
||||||
|
model = StudentRegistration
|
||||||
|
autocomplete_fields = ('team',)
|
||||||
|
show_change_link = True
|
||||||
|
|
||||||
|
class CoachRegistrationInline(StackedPolymorphicInline.Child):
|
||||||
|
model = CoachRegistration
|
||||||
|
autocomplete_fields = ('team',)
|
||||||
|
show_change_link = True
|
||||||
|
|
||||||
|
class VolunteerRegistrationInline(StackedPolymorphicInline.Child):
|
||||||
|
model = VolunteerRegistration
|
||||||
|
show_change_link = True
|
||||||
|
|
||||||
|
model = Registration
|
||||||
|
child_inlines = (
|
||||||
|
StudentRegistrationInline,
|
||||||
|
CoachRegistrationInline,
|
||||||
|
VolunteerRegistrationInline,
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
class PaymentInline(admin.TabularInline):
|
||||||
|
model = Payment
|
||||||
|
extra = 0
|
||||||
|
autocomplete_fields = ('registrations',)
|
||||||
|
|
||||||
|
|
||||||
@admin.register(Registration)
|
@admin.register(Registration)
|
||||||
class RegistrationAdmin(PolymorphicParentModelAdmin):
|
class RegistrationAdmin(PolymorphicParentModelAdmin):
|
||||||
child_models = (StudentRegistration, CoachRegistration, VolunteerRegistration,)
|
child_models = (StudentRegistration, CoachRegistration, VolunteerRegistration,)
|
||||||
|
@ -97,12 +129,34 @@ class VolunteerRegistrationAdmin(PolymorphicChildModelAdmin):
|
||||||
|
|
||||||
@admin.register(Payment)
|
@admin.register(Payment)
|
||||||
class PaymentAdmin(ModelAdmin):
|
class PaymentAdmin(ModelAdmin):
|
||||||
list_display = ('id', 'concerned_people', 'grouped', 'type', 'valid', )
|
list_display = ('concerned_people', 'tournament', 'team', 'grouped', 'type', 'amount', 'valid', )
|
||||||
search_fields = ('registrations__user__last_name', 'registrations__user__first_name', 'registrations__user__email',)
|
search_fields = ('registrations__user__last_name', 'registrations__user__first_name', 'registrations__user__email',
|
||||||
|
'registrations__team__name', 'registrations__team__participation__team__trigram',)
|
||||||
list_filter = ('registrations__team__participation__valid', 'type',
|
list_filter = ('registrations__team__participation__valid', 'type',
|
||||||
'grouped', 'valid', 'registrations__polymorphic_ctype',)
|
'grouped', 'valid', 'registrations__team__participation__tournament', 'final',)
|
||||||
autocomplete_fields = ('registrations',)
|
autocomplete_fields = ('registrations',)
|
||||||
|
actions = ('mark_as_valid', 'mark_as_pending', 'mark_as_invalid',)
|
||||||
|
|
||||||
@admin.display(description=_('concerned people'))
|
@admin.display(description=_('concerned people'))
|
||||||
def concerned_people(self, record: Payment):
|
def concerned_people(self, record: Payment):
|
||||||
return ", ".join(f"{reg.user.first_name} {reg.user.last_name}" for reg in record.registrations.all())
|
return ", ".join(f"{reg.user.first_name} {reg.user.last_name}" for reg in record.registrations.all())
|
||||||
|
|
||||||
|
@admin.action(description=_('Mark as valid'))
|
||||||
|
def mark_as_valid(self, request, queryset):
|
||||||
|
queryset.update(valid=True)
|
||||||
|
|
||||||
|
@admin.action(description=_('Mark as pending'))
|
||||||
|
def mark_as_pending(self, request, queryset):
|
||||||
|
queryset.update(valid=None)
|
||||||
|
|
||||||
|
@admin.action(description=_('Mark as invalid'))
|
||||||
|
def mark_as_invalid(self, request, queryset):
|
||||||
|
queryset.update(valid=False)
|
||||||
|
|
||||||
|
|
||||||
|
admin.site.unregister(User)
|
||||||
|
|
||||||
|
|
||||||
|
@admin.register(User)
|
||||||
|
class UserCustomAdmin(PolymorphicInlineSupportMixin, UserAdmin):
|
||||||
|
inlines = [RegistrationInline]
|
||||||
|
|
|
@ -589,6 +589,8 @@ class Payment(models.Model):
|
||||||
@property
|
@property
|
||||||
def team(self):
|
def team(self):
|
||||||
return self.registrations.first().team
|
return self.registrations.first().team
|
||||||
|
team.fget.short_description = _("team")
|
||||||
|
team.fget.admin_order_field = 'registrations__team__trigram'
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def tournament(self):
|
def tournament(self):
|
||||||
|
@ -596,6 +598,8 @@ class Payment(models.Model):
|
||||||
from participation.models import Tournament
|
from participation.models import Tournament
|
||||||
return Tournament.final_tournament()
|
return Tournament.final_tournament()
|
||||||
return self.registrations.first().team.participation.tournament
|
return self.registrations.first().team.participation.tournament
|
||||||
|
tournament.fget.short_description = _("tournament")
|
||||||
|
tournament.fget.admin_order_field = 'registrations__team__participation__tournament'
|
||||||
|
|
||||||
def get_checkout_intent(self, none_if_link_disabled=False):
|
def get_checkout_intent(self, none_if_link_disabled=False):
|
||||||
if self.checkout_intent_id is None:
|
if self.checkout_intent_id is None:
|
||||||
|
|
Loading…
Reference in New Issue