From 286c075ea82c027676e8047fce4863c75b303511 Mon Sep 17 00:00:00 2001 From: Olivier DOSSMANN Date: Sun, 4 Feb 2018 21:34:05 +0100 Subject: [PATCH] =?UTF-8?q?Am=C3=A9lioration=20du=20nom=20affich=C3=A9=20p?= =?UTF-8?q?our=20le=20filtre=20sur=20les=20Chronologies?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- collection/games/admin.py | 25 ++++++++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) diff --git a/collection/games/admin.py b/collection/games/admin.py index 9a588a7..0811c3b 100644 --- a/collection/games/admin.py +++ b/collection/games/admin.py @@ -80,10 +80,33 @@ class GameAdmin(admin.ModelAdmin): get_platform.admin_order_field = 'collection__shortname' +class TimelinePlatformFilter(admin.SimpleListFilter): + """ + Display Platform shortname. + """ + title = _('platform') + parameter_name = 'collection' + + def lookups(self, request, model_admin): + """ + Get all platforms + """ + return [(x.id, x.shortname) for x in Platform.objects.all()] + + def queryset(self, request, queryset): + """ + Filter on 'shortname' field. + """ + if self.value(): + return queryset.filter(item__collection__id=self.value()) + else: + return queryset + + class TimelineAdmin(admin.ModelAdmin): list_display = ('date', 'status', 'item', 'get_platform') search_fields = ('item__name', ) - list_filter = ('item__collection__shortname', ) + list_filter = (TimelinePlatformFilter, ) def get_platform(self, obj): """