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