from django.contrib import admin from django.utils.translation import ugettext as _ from games.forms import GameForm from games.models import Game, Platform, 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 = [ StatusFilter, 'playing', 'wish'] search_fields = ('name',) fieldsets = [ (_('Game Information'), { 'fields': [ ('name', 'collection')]}), (_('Progress'), {'fields': [ ('status'), ('note')]}), ('', {'fields': [ ('playing'), ('unplayed'), ('wish')]}) ] form = GameForm class TimelineAdmin(admin.ModelAdmin): list_display = ( 'date', 'status', 'item') admin.site.register(Platform) admin.site.register(Game, GameAdmin) admin.site.register(Timeline, TimelineAdmin)