summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--meetingtools/apps/room/admin.py25
1 files changed, 25 insertions, 0 deletions
diff --git a/meetingtools/apps/room/admin.py b/meetingtools/apps/room/admin.py
index 73235f3..d0cc74c 100644
--- a/meetingtools/apps/room/admin.py
+++ b/meetingtools/apps/room/admin.py
@@ -4,12 +4,37 @@ Created on Jan 31, 2011
@author: leifj
'''
+from datetime import date
from django.contrib import admin
from meetingtools.apps.room.models import Room
+class YearLastVisitedFilter(admin.SimpleListFilter):
+ title = 'year last visited'
+ parameter_name = 'year'
+
+ def lookups(self, request, model_admin):
+ return (
+ ('None', 'None'),
+ ('2012', '2012'),
+ ('2013', '2013'),
+ ('2014', '2014'),
+ )
+
+ def queryset(self, request, queryset):
+ if self.value() == 'None':
+ return queryset.filter(lastvisited=None)
+ try:
+ year = int(self.value())
+ return queryset.filter(lastvisited__gte=date(year, 1, 1), lastvisited__lte=date(year, 12, 31))
+ except TypeError:
+ return None
+
+
class RoomAdmin(admin.ModelAdmin):
date_hierarchy = 'timecreated'
+ search_fields = ['creator__username', 'name', 'sco__sco_id']
list_display = ('timecreated', 'creator', 'name', 'urlpath', 'sco', 'deleted_sco', 'lastupdated', 'lastvisited')
+ list_filter = (YearLastVisitedFilter,)
admin.site.register(Room, RoomAdmin) \ No newline at end of file