Ajout d'un filter par plateforme sur les jeux (Game)
This commit is contained in:
@ -33,9 +33,32 @@ class StatusFilter(admin.SimpleListFilter):
|
||||
return queryset
|
||||
|
||||
|
||||
class PlatformFilter(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(collection__id=self.value())
|
||||
else:
|
||||
return queryset
|
||||
|
||||
|
||||
class GameAdmin(admin.ModelAdmin):
|
||||
list_display = ('name', 'get_platform', 'playing', 'status', 'wish')
|
||||
list_filter = [StatusFilter, 'playing', 'wish']
|
||||
list_filter = [StatusFilter, 'playing', 'wish', PlatformFilter]
|
||||
search_fields = ('name', )
|
||||
fieldsets = [(_('Game Information'), {
|
||||
'fields': [('name', 'collection')]
|
||||
|
Reference in New Issue
Block a user