From 7a2bd58ef89b7a77d5121164ac69a0003af629c3 Mon Sep 17 00:00:00 2001 From: Jonas Winkler Date: Wed, 4 Jul 2018 17:10:56 +0200 Subject: [PATCH] Updated date filter to use the drilldown feature of django --- src/documents/admin.py | 30 +++--------------------------- 1 file changed, 3 insertions(+), 27 deletions(-) diff --git a/src/documents/admin.py b/src/documents/admin.py index 6a32edc9b..2a11d5ddd 100755 --- a/src/documents/admin.py +++ b/src/documents/admin.py @@ -10,31 +10,6 @@ from django.utils.safestring import mark_safe from .models import Correspondent, Tag, Document, Log -class MonthListFilter(admin.SimpleListFilter): - - title = "Month" - - # Parameter for the filter that will be used in the URL query. - parameter_name = "month" - - def lookups(self, request, model_admin): - r = [] - for document in Document.objects.all(): - r.append(( - document.created.strftime("%Y-%m"), - document.created.strftime("%B %Y") - )) - return sorted(set(r), key=lambda x: x[0], reverse=True) - - def queryset(self, request, queryset): - - if not self.value(): - return None - - year, month = self.value().split("-") - return queryset.filter(created__year=year, created__month=month) - - class FinancialYearFilter(admin.SimpleListFilter): title = "Financial Year" @@ -129,11 +104,12 @@ class DocumentAdmin(CommonAdmin): readonly_fields = ("added",) list_display = ("title", "created", "added", "thumbnail", "correspondent", "tags_") - list_filter = ("tags", "correspondent", FinancialYearFilter, - MonthListFilter) + list_filter = ("tags", "correspondent", FinancialYearFilter) ordering = ["-created", "correspondent"] + date_hierarchy = 'created' + def has_add_permission(self, request): return False