From 64ef1b8086d253fa1a7c9ef93d93620ea75c3b35 Mon Sep 17 00:00:00 2001 From: Olivier DOSSMANN Date: Thu, 18 Jan 2018 20:57:06 +0100 Subject: [PATCH] Ajout d'un filter par plateforme sur les jeux (Game) --- .../conf/locale/fr/LC_MESSAGES/django.po | 26 +++++++++---------- collection/games/admin.py | 25 +++++++++++++++++- 2 files changed, 37 insertions(+), 14 deletions(-) diff --git a/collection/conf/locale/fr/LC_MESSAGES/django.po b/collection/conf/locale/fr/LC_MESSAGES/django.po index 1c86ce4..24b47b3 100644 --- a/collection/conf/locale/fr/LC_MESSAGES/django.po +++ b/collection/conf/locale/fr/LC_MESSAGES/django.po @@ -7,7 +7,7 @@ msgid "" msgstr "" "Project-Id-Version: 0.1\n" "Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2018-01-15 20:10+0000\n" +"POT-Creation-Date: 2018-01-18 19:55+0000\n" "PO-Revision-Date: 2018-01-15 21:10+0100\n" "Last-Translator: \n" "Language-Team: \n" @@ -17,23 +17,23 @@ msgstr "" "Content-Transfer-Encoding: 8bit\n" "X-Generator: Poedit 2.0.5\n" -#: core/models.py:8 core/models.py:28 +#: core/models.py:9 core/models.py:29 msgid "name" msgstr "nom" -#: core/models.py:9 +#: core/models.py:10 msgid "shortname" msgstr "nom court" -#: core/models.py:25 +#: core/models.py:26 msgid "New" msgstr "Nouveau" -#: core/models.py:48 core/models.py:79 +#: core/models.py:49 core/models.py:82 msgid "status" msgstr "état" -#: core/models.py:65 +#: core/models.py:68 msgid "date" msgstr "date" @@ -73,22 +73,22 @@ msgstr "Progression de la figurine" msgid "state" msgstr "état" -#: games/admin.py:40 +#: games/admin.py:40 games/models.py:15 games/models.py:29 +msgid "platform" +msgstr "plateforme" + +#: games/admin.py:63 msgid "Game Information" msgstr "Information du jeu" -#: games/admin.py:42 +#: games/admin.py:65 msgid "Progress" msgstr "Progression" -#: games/admin.py:56 +#: games/admin.py:79 msgid "Platform" msgstr "Plateforme" -#: games/models.py:15 games/models.py:29 -msgid "platform" -msgstr "plateforme" - #: games/models.py:16 msgid "platforms" msgstr "plateformes" diff --git a/collection/games/admin.py b/collection/games/admin.py index 4c455e0..459ada3 100644 --- a/collection/games/admin.py +++ b/collection/games/admin.py @@ -33,9 +33,32 @@ class StatusFilter(admin.SimpleListFilter): return queryset +class PlatformFilter(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(collection__id=self.value()) + else: + return queryset + + class GameAdmin(admin.ModelAdmin): list_display = ('name', 'get_platform', 'playing', 'status', 'wish') - list_filter = [StatusFilter, 'playing', 'wish'] + list_filter = [StatusFilter, 'playing', 'wish', PlatformFilter] search_fields = ('name', ) fieldsets = [(_('Game Information'), { 'fields': [('name', 'collection')]