mirror of
https://github.com/paperless-ngx/paperless-ngx.git
synced 2025-04-02 13:45:10 -05:00
Updated date filter to use the drilldown feature of django
This commit is contained in:
parent
8f6231bd34
commit
7a2bd58ef8
@ -10,31 +10,6 @@ from django.utils.safestring import mark_safe
|
|||||||
from .models import Correspondent, Tag, Document, Log
|
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):
|
class FinancialYearFilter(admin.SimpleListFilter):
|
||||||
|
|
||||||
title = "Financial Year"
|
title = "Financial Year"
|
||||||
@ -129,11 +104,12 @@ class DocumentAdmin(CommonAdmin):
|
|||||||
readonly_fields = ("added",)
|
readonly_fields = ("added",)
|
||||||
list_display = ("title", "created", "added", "thumbnail", "correspondent",
|
list_display = ("title", "created", "added", "thumbnail", "correspondent",
|
||||||
"tags_")
|
"tags_")
|
||||||
list_filter = ("tags", "correspondent", FinancialYearFilter,
|
list_filter = ("tags", "correspondent", FinancialYearFilter)
|
||||||
MonthListFilter)
|
|
||||||
|
|
||||||
ordering = ["-created", "correspondent"]
|
ordering = ["-created", "correspondent"]
|
||||||
|
|
||||||
|
date_hierarchy = 'created'
|
||||||
|
|
||||||
def has_add_permission(self, request):
|
def has_add_permission(self, request):
|
||||||
return False
|
return False
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user