diff options
author | Johan Lundberg <lundberg@nordu.net> | 2014-03-27 16:26:35 +0100 |
---|---|---|
committer | Johan Lundberg <lundberg@nordu.net> | 2014-03-27 16:26:35 +0100 |
commit | d9b769f2ecda67c8953fbde4c4b1808e8531411a (patch) | |
tree | dcad1b9143d6fad8839fadabf85a6fce99761356 /meetingtools/apps | |
parent | ea6655acf83caed4291f2ae3656da04d20e23870 (diff) |
Added YearLastVisitedFilter list filter to room admin.
Diffstat (limited to 'meetingtools/apps')
-rw-r--r-- | meetingtools/apps/room/admin.py | 25 |
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 |