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
|
2017-09-16 15:42:04 +00:00
|
|
|
from games.models import Game, Platform, Timeline
|
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
|
|
|
|
|
|
|
|
|
2017-08-17 20:42:48 +00:00
|
|
|
class GameAdmin(admin.ModelAdmin):
|
|
|
|
list_display = (
|
|
|
|
'name', 'playing', 'status', 'wish')
|
|
|
|
list_filter = [
|
2017-08-25 21:51:37 +00:00
|
|
|
StatusFilter,
|
2017-08-17 20:42:48 +00:00
|
|
|
'playing',
|
|
|
|
'wish']
|
|
|
|
search_fields = ('name',)
|
2017-08-25 22:23:56 +00:00
|
|
|
fieldsets = [
|
|
|
|
(_('Game Information'), {
|
|
|
|
'fields': [
|
|
|
|
('name', 'collection')]}),
|
|
|
|
(_('Progress'),
|
|
|
|
{'fields': [
|
|
|
|
('status'),
|
|
|
|
('note')]}),
|
|
|
|
('',
|
|
|
|
{'fields': [
|
|
|
|
('playing'), ('unplayed'), ('wish')]})
|
2017-08-24 18:43:58 +00:00
|
|
|
]
|
2017-08-17 20:42:48 +00:00
|
|
|
|
2017-08-25 21:51:37 +00:00
|
|
|
form = GameForm
|
|
|
|
|
2017-08-22 19:02:43 +00:00
|
|
|
|
|
|
|
class TimelineAdmin(admin.ModelAdmin):
|
|
|
|
list_display = (
|
|
|
|
'date', 'status', 'item')
|
|
|
|
|
|
|
|
|
2017-09-16 15:42:04 +00:00
|
|
|
admin.site.register(Platform)
|
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)
|