diff --git a/collection/games/admin.py b/collection/games/admin.py index 9a588a7..0811c3b 100644 --- a/collection/games/admin.py +++ b/collection/games/admin.py @@ -80,10 +80,33 @@ class GameAdmin(admin.ModelAdmin): get_platform.admin_order_field = 'collection__shortname' +class TimelinePlatformFilter(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(item__collection__id=self.value()) + else: + return queryset + + class TimelineAdmin(admin.ModelAdmin): list_display = ('date', 'status', 'item', 'get_platform') search_fields = ('item__name', ) - list_filter = ('item__collection__shortname', ) + list_filter = (TimelinePlatformFilter, ) def get_platform(self, obj): """