2017-08-16 20:00:41 +00:00
|
|
|
from django.contrib import admin
|
2017-08-25 21:51:37 +00:00
|
|
|
from django.utils.translation import ugettext as _
|
|
|
|
from games.forms import GameForm
|
2018-01-15 18:07:19 +00:00
|
|
|
from games.models import Game
|
|
|
|
from games.models import Platform
|
|
|
|
from games.models import Timeline
|
|
|
|
|
|
|
|
|
|
|
|
class PlatformAdmin(admin.ModelAdmin):
|
|
|
|
list_display = ('shortname', 'name')
|
2017-08-16 20:00:41 +00:00
|
|
|
|
|
|
|
|
2017-08-25 21:51:37 +00:00
|
|
|
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
|
|
|
|
|
|
|
|
|
2018-01-18 19:57:06 +00:00
|
|
|
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
|
|
|
|
|
|
|
|
|
2017-08-17 20:42:48 +00:00
|
|
|
class GameAdmin(admin.ModelAdmin):
|
2018-01-15 20:13:49 +00:00
|
|
|
list_display = ('name', 'get_platform', 'playing', 'status', 'wish')
|
2018-01-18 19:59:53 +00:00
|
|
|
list_filter = [StatusFilter, PlatformFilter, 'playing', 'wish']
|
2018-01-15 18:07:19 +00:00
|
|
|
search_fields = ('name', )
|
|
|
|
fieldsets = [(_('Game Information'), {
|
|
|
|
'fields': [('name', 'collection')]
|
|
|
|
}), (_('Progress'), {
|
2018-01-21 11:38:18 +00:00
|
|
|
'fields': [('status'), ('achievement', 'achievement_max'), ('note')]
|
2018-01-15 18:07:19 +00:00
|
|
|
}), ('', {
|
|
|
|
'fields': [('playing'), ('unplayed'), ('wish')]
|
|
|
|
})]
|
2017-08-17 20:42:48 +00:00
|
|
|
|
2017-08-25 21:51:37 +00:00
|
|
|
form = GameForm
|
|
|
|
|
2018-01-15 20:13:49 +00:00
|
|
|
def get_platform(self, obj):
|
|
|
|
"""
|
|
|
|
Display platform shortname
|
|
|
|
"""
|
|
|
|
return obj.collection.shortname
|
|
|
|
|
|
|
|
get_platform.short_description = _('Platform')
|
|
|
|
get_platform.admin_order_field = 'collection__shortname'
|
|
|
|
|
2017-08-22 19:02:43 +00:00
|
|
|
|
2018-02-04 20:34:05 +00:00
|
|
|
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
|
|
|
|
|
|
|
|
|
2017-08-22 19:02:43 +00:00
|
|
|
class TimelineAdmin(admin.ModelAdmin):
|
2018-02-04 20:27:43 +00:00
|
|
|
list_display = ('date', 'status', 'item', 'get_platform')
|
2018-02-04 13:43:10 +00:00
|
|
|
search_fields = ('item__name', )
|
2018-02-04 20:34:05 +00:00
|
|
|
list_filter = (TimelinePlatformFilter, )
|
2018-02-04 20:27:43 +00:00
|
|
|
|
|
|
|
def get_platform(self, obj):
|
|
|
|
"""
|
|
|
|
Display platform shortname
|
|
|
|
"""
|
|
|
|
return obj.item.collection.shortname
|
|
|
|
|
|
|
|
get_platform.short_description = _('Platform')
|
|
|
|
get_platform.admin_order_field = ('item__collection__shortname')
|
2017-08-22 19:02:43 +00:00
|
|
|
|
|
|
|
|
2018-01-15 18:07:19 +00:00
|
|
|
admin.site.register(Platform, PlatformAdmin)
|
2017-08-17 20:42:48 +00:00
|
|
|
admin.site.register(Game, GameAdmin)
|
2017-08-22 19:02:43 +00:00
|
|
|
admin.site.register(Timeline, TimelineAdmin)
|