Add Game column to SongRequest admin page.
This commit is contained in:
parent
568b3f2f66
commit
d4022bdb31
1 changed files with 19 additions and 5 deletions
|
@ -41,11 +41,14 @@ class ProfileAdmin(admin.ModelAdmin):
|
||||||
@admin.register(SongRequest)
|
@admin.register(SongRequest)
|
||||||
class RequestAdmin(admin.ModelAdmin):
|
class RequestAdmin(admin.ModelAdmin):
|
||||||
# Detail List display
|
# Detail List display
|
||||||
list_display = ('get_user',
|
list_display = (
|
||||||
|
'get_user',
|
||||||
|
'get_game',
|
||||||
'song',
|
'song',
|
||||||
'created_date',
|
'created_date',
|
||||||
'queued_at',
|
'queued_at',
|
||||||
'played_at')
|
'played_at'
|
||||||
|
)
|
||||||
search_fields = ['song', 'profile']
|
search_fields = ['song', 'profile']
|
||||||
|
|
||||||
# Edit Form display
|
# Edit Form display
|
||||||
|
@ -61,8 +64,19 @@ class RequestAdmin(admin.ModelAdmin):
|
||||||
verbose_name_plural = 'requests'
|
verbose_name_plural = 'requests'
|
||||||
extra = 0
|
extra = 0
|
||||||
|
|
||||||
|
def get_queryset(self, request):
|
||||||
|
return super(
|
||||||
|
RequestAdmin, self
|
||||||
|
).get_queryset(request).select_related('profile__user', 'song__game')
|
||||||
|
|
||||||
def get_user(self, obj):
|
def get_user(self, obj):
|
||||||
'''Returns the username from the profile.'''
|
'''Returns the username from the profile.'''
|
||||||
return obj.profile.user
|
return obj.profile.user
|
||||||
get_user.admin_order_field = 'profile'
|
get_user.admin_order_field = 'profile'
|
||||||
get_user.short_description = 'User Name'
|
get_user.short_description = 'User Name'
|
||||||
|
|
||||||
|
def get_game(self, obj):
|
||||||
|
'''Returns the game associated with the song.'''
|
||||||
|
return obj.song.game
|
||||||
|
get_game.admin_order_field = 'song__game'
|
||||||
|
get_game.short_description = 'Game'
|
||||||
|
|
Loading…
Reference in a new issue