1
0
mirror of https://gitlab.com/animath/si/plateforme.git synced 2025-06-21 22:38:23 +02:00

Improve Django-admin interface, inlines and filters

Signed-off-by: Emmy D'Anello <emmy.danello@animath.fr>
This commit is contained in:
Emmy D'Anello
2024-02-23 21:43:44 +01:00
parent cae1c6fdb8
commit de504398d2
6 changed files with 372 additions and 185 deletions

View File

@ -7,11 +7,34 @@ from django.utils.translation import gettext_lazy as _
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)
class DrawAdmin(admin.ModelAdmin):
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',)
autocomplete_fields = ('tournament',)
inlines = (RoundInline,)
@admin.display(description=_("teams"))
def teams(self, record: Draw):
@ -20,10 +43,16 @@ class DrawAdmin(admin.ModelAdmin):
@admin.register(Round)
class RoundAdmin(admin.ModelAdmin):
list_display = ('draw', 'number', 'teams',)
list_display = ('draw', 'tournament', 'number', 'teams',)
list_filter = ('draw__tournament', 'number',)
search_fields = ('draw__tournament__name', 'pool__teamdraw__participation__team__trigram')
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"))
def teams(self, record: Round):
@ -36,6 +65,8 @@ class PoolAdmin(admin.ModelAdmin):
list_filter = ('round__draw__tournament', 'round__number', 'letter')
ordering = ('round__draw__tournament__name', 'round', 'letter')
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"))
def tournament(self, record):
@ -52,6 +83,7 @@ class TeamDrawAdmin(admin.ModelAdmin):
'passage_index', 'choose_index', 'passage_dice', 'choice_dice',)
list_filter = ('round__draw__tournament', 'round__number', 'pool__letter',)
search_fields = ('round__draw__tournament__name', 'participation__team__trigram',)
autocomplete_fields = ('participation', 'round', 'pool',)
@admin.display(ordering='round__draw__tournament__name', description=_("tournament"))
def tournament(self, record):

View File

@ -89,6 +89,7 @@ class Draw(models.Model):
return 'WAITING_DRAW_PROBLEM'
else:
return 'WAITING_CHOOSE_PROBLEM'
get_state.short_description = _('State')
@property
def information(self):