From 6319f244998f0d36d59223a4683871ec75715675 Mon Sep 17 00:00:00 2001 From: Olivier DOSSMANN Date: Fri, 25 Aug 2017 23:51:37 +0200 Subject: [PATCH] =?UTF-8?q?Omission=20de=20l'=C3=A9tat=20'Nouveau'=20(CREA?= =?UTF-8?q?TED)=20dans=20les=20formulaires=20et=20le=20filtre?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- CHANGELOG | 2 ++ collection/games/admin.py | 29 ++++++++++++++++++++++++++++- collection/games/forms.py | 12 ++++++++++++ 3 files changed, 42 insertions(+), 1 deletion(-) create mode 100644 collection/games/forms.py diff --git a/CHANGELOG b/CHANGELOG index c5f3444..c7d7308 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -1,10 +1,12 @@ Current version (0.2) : + - Omission de l'état "Nouveau" pour les jeux - Traduction de l'interface en Français - Aide contextuelle sur l'interface admin d'un jeu vidéo Version 0.1 : + - Application de la licence EUPL v1.2 - Utilisation possible de l'application par Docker - Interface web d'administration - Liste de jeux joués diff --git a/collection/games/admin.py b/collection/games/admin.py index 8bb2921..2326566 100644 --- a/collection/games/admin.py +++ b/collection/games/admin.py @@ -1,12 +1,37 @@ from django.contrib import admin +from django.utils.translation import ugettext as _ +from games.forms import GameForm from games.models import Console, Game, Timeline +class StatusFilter(admin.SimpleListFilter): + """ + Remove CREATED status. + """ + title = _('state') + parameter_name = 'status' + + def lookups(self, request, model_admin): + """ + Return only games choices (not CREATED from Item abstract class). + """ + return Game.STATUS_CHOICES + + def queryset(self, request, queryset): + """ + Filter on 'status' field. + """ + if self.value(): + return queryset.filter(status=self.value()) + else: + return queryset + + class GameAdmin(admin.ModelAdmin): list_display = ( 'name', 'playing', 'status', 'wish') list_filter = [ - 'status', + StatusFilter, 'playing', 'wish'] search_fields = ('name',) @@ -19,6 +44,8 @@ class GameAdmin(admin.ModelAdmin): 'wish' ] + form = GameForm + class TimelineAdmin(admin.ModelAdmin): list_display = ( diff --git a/collection/games/forms.py b/collection/games/forms.py new file mode 100644 index 0000000..9fd1859 --- /dev/null +++ b/collection/games/forms.py @@ -0,0 +1,12 @@ +from django import forms +from games.models import Game + + +class GameForm(forms.ModelForm): + def __init__(self, *args, **kwargs): + """ + Do not display CREATED status. + """ + super(GameForm, self).__init__(*args, **kwargs) + + self.fields['status'].choices = Game.STATUS_CHOICES