Skip to content

A community-supported supercharged document management system: scan, index and archive all your documents

Fix the correspondent filters #423

Daniel Quinneca6250c1b7f
diff --git a/docs/changelog.rst b/docs/changelog.rst
index d2effb3ac..e98436382 100644
--- a/docs/changelog.rst
+++ b/docs/changelog.rst
@@ -6,6 +6,9 @@ Changelog
* Allow an infinite number of logs to be deleted. Thanks to `Ulli`_ for noting
the problem in `#433`_.
+* Fix the ``RecentCorrespondentsFilter`` correspondents filter that was added
+ in 2.4 to play nice with the defaults. Thanks to `tsia`_ and `Sblop`_ who
+ pointed this out. `#423`_.
2.5.0
@@ -579,6 +582,8 @@ bulk of the work on this big change.
.. _Andrew Peng: https://github.com/pengc99
.. _euri10: https://github.com/euri10
.. _Ulli: https://github.com/Ulli2k
+.. _tsia: https://github.com/tsia
+.. _Sblop: https://github.com/Sblop
.. _#20: https://github.com/danielquinn/paperless/issues/20
.. _#44: https://github.com/danielquinn/paperless/issues/44
@@ -673,6 +678,7 @@ bulk of the work on this big change.
.. _#412: https://github.com/danielquinn/paperless/issues/412
.. _#413: https://github.com/danielquinn/paperless/pull/413
.. _#414: https://github.com/danielquinn/paperless/issues/414
+.. _#423: https://github.com/danielquinn/paperless/issues/423
.. _#433: https://github.com/danielquinn/paperless/issues/433
.. _pipenv: https://docs.pipenv.org/
diff --git a/src/documents/admin.py b/src/documents/admin.py
index 6c0424a74..e61d14815 100644
--- a/src/documents/admin.py
+++ b/src/documents/admin.py
@@ -88,25 +88,24 @@ class FinancialYearFilter(admin.SimpleListFilter):
class RecentCorrespondentFilter(admin.RelatedFieldListFilter):
-
- def __init__(self, *args, **kwargs):
- super().__init__(*args, **kwargs)
- self.title = "correspondent (recent)"
+ """
+ If PAPERLESS_RECENT_CORRESPONDENT_YEARS is set, we limit the available
+ correspondents to documents sent our way over the past ``n`` years.
+ """
def field_choices(self, field, request, model_admin):
years = settings.PAPERLESS_RECENT_CORRESPONDENT_YEARS
- days = 365 * years
+ correspondents = Correspondent.objects.all()
- lookups = []
if years and years > 0:
- correspondents = Correspondent.objects.filter(
+ self.title = "Correspondent (Recent)"
+ days = 365 * years
+ correspondents = correspondents.filter(
documents__created__gte=datetime.now() - timedelta(days=days)
).distinct()
- for c in correspondents:
- lookups.append((c.id, c.name))
- return lookups
+ return [(c.id, c.name) for c in correspondents]
class CommonAdmin(admin.ModelAdmin):
@@ -177,7 +176,6 @@ class DocumentAdmin(CommonAdmin):
list_filter = (
"tags",
("correspondent", RecentCorrespondentFilter),
- "correspondent",
FinancialYearFilter
)