From aeb10d34079bb62d5d748698062de0bfa9a20585 Mon Sep 17 00:00:00 2001 From: jonaswinkler Date: Thu, 21 Jan 2021 12:07:50 +0100 Subject: [PATCH] fixes duplicate documents with tags__id__in --- src/documents/tests/test_api.py | 6 ++++++ src/documents/views.py | 3 +++ 2 files changed, 9 insertions(+) diff --git a/src/documents/tests/test_api.py b/src/documents/tests/test_api.py index 6b9cf14e0..2b332a873 100644 --- a/src/documents/tests/test_api.py +++ b/src/documents/tests/test_api.py @@ -228,6 +228,12 @@ class TestDocumentApi(DirectoriesMixin, APITestCase): self.assertEqual(len(results), 2) self.assertCountEqual([results[0]['id'], results[1]['id']], [doc1.id, doc3.id]) + response = self.client.get("/api/documents/?tags__id__in={},{}".format(tag_2.id, tag_3.id)) + self.assertEqual(response.status_code, 200) + results = response.data['results'] + self.assertEqual(len(results), 2) + self.assertCountEqual([results[0]['id'], results[1]['id']], [doc2.id, doc3.id]) + response = self.client.get("/api/documents/?tags__id__all={},{}".format(tag_2.id, tag_3.id)) self.assertEqual(response.status_code, 200) results = response.data['results'] diff --git a/src/documents/views.py b/src/documents/views.py index eb9078f75..b99bf11c7 100755 --- a/src/documents/views.py +++ b/src/documents/views.py @@ -159,6 +159,9 @@ class DocumentViewSet(RetrieveModelMixin, "added", "archive_serial_number") + def get_queryset(self): + return Document.objects.distinct() + def get_serializer(self, *args, **kwargs): fields_param = self.request.query_params.get('fields', None) if fields_param: