from django.contrib import admin from django.utils.translation import ugettext as _ from games.forms import GameForm from games.models import Game from games.models import Platform from games.models import Timeline class PlatformAdmin(admin.ModelAdmin): list_display = ('shortname', 'name') 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', 'get_platform', '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 def get_platform(self, obj): """ Display platform shortname """ return obj.collection.shortname get_platform.short_description = _('Platform') get_platform.admin_order_field = 'collection__shortname' class TimelineAdmin(admin.ModelAdmin): list_display = ('date', 'status', 'item') admin.site.register(Platform, PlatformAdmin) admin.site.register(Game, GameAdmin) admin.site.register(Timeline, TimelineAdmin)