Amélioration du nom affiché pour le filtre sur les Chronologies

This commit is contained in:
Olivier DOSSMANN 2018-02-04 21:34:05 +01:00
parent 2e7123989f
commit 286c075ea8

View File

@ -80,10 +80,33 @@ class GameAdmin(admin.ModelAdmin):
get_platform.admin_order_field = 'collection__shortname' 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): class TimelineAdmin(admin.ModelAdmin):
list_display = ('date', 'status', 'item', 'get_platform') list_display = ('date', 'status', 'item', 'get_platform')
search_fields = ('item__name', ) search_fields = ('item__name', )
list_filter = ('item__collection__shortname', ) list_filter = (TimelinePlatformFilter, )
def get_platform(self, obj): def get_platform(self, obj):
""" """