From e9a21088db98a6e1b4589f463a5cc36ae84bcba8 Mon Sep 17 00:00:00 2001 From: shamoon <4887959+shamoon@users.noreply.github.com> Date: Fri, 30 Jan 2026 00:49:19 -0800 Subject: [PATCH] More cleanup --- src/documents/permissions.py | 2 +- src/documents/views.py | 9 ++------- 2 files changed, 3 insertions(+), 8 deletions(-) diff --git a/src/documents/permissions.py b/src/documents/permissions.py index b8ec01d7e..4b19db1ce 100644 --- a/src/documents/permissions.py +++ b/src/documents/permissions.py @@ -193,7 +193,7 @@ def annotate_document_count_for_related_queryset( queryset, through_model, source_field: str, - target_field: str, + target_field: str = "document_id", user=None, ): """ diff --git a/src/documents/views.py b/src/documents/views.py index 555e286e5..3684ff84d 100644 --- a/src/documents/views.py +++ b/src/documents/views.py @@ -375,7 +375,6 @@ class PermissionsAwareDocumentCountMixin(BulkPermissionMixin, PassUserMixin): document_count_relation = "documents" document_count_through = None # set to relation model to enable through counting document_count_source_field = None - document_count_target_field = None def get_document_count_filter(self): request = getattr(self, "request", None) @@ -392,7 +391,6 @@ class PermissionsAwareDocumentCountMixin(BulkPermissionMixin, PassUserMixin): base_qs, through_model=self.document_count_through, source_field=self.document_count_source_field, - target_field=self.document_count_target_field, user=user, ) @@ -445,7 +443,6 @@ class TagViewSet(PermissionsAwareDocumentCountMixin, ModelViewSet): model = Tag document_count_through = Document.tags.through document_count_source_field = "tag_id" - document_count_target_field = "document_id" queryset = Tag.objects.select_related("owner").order_by( Lower("name"), @@ -494,9 +491,8 @@ class TagViewSet(PermissionsAwareDocumentCountMixin, ModelViewSet): Tag.objects.filter(pk__in=descendant_pks | {t.pk for t in all_tags}) .select_related("owner") .order_by(*ordering), - through_model=Document.tags.through, - source_field="tag_id", - target_field="document_id", + through_model=self.document_count_through, + source_field=self.document_count_source_field, user=user, ), ) @@ -2900,7 +2896,6 @@ class CustomFieldViewSet(PermissionsAwareDocumentCountMixin, ModelViewSet): model = CustomField document_count_through = CustomFieldInstance document_count_source_field = "field_id" - document_count_target_field = "document_id" queryset = CustomField.objects.all().order_by("-created")