Include on single correspondents
This commit is contained in:
parent
979d0acb75
commit
d88085b12f
@ -98,7 +98,7 @@ class TestApiObjects(DirectoriesMixin, APITestCase):
|
||||
WHEN:
|
||||
- API is called
|
||||
THEN:
|
||||
- Last correspondence date is returned only if requested
|
||||
- Last correspondence date is returned only if requested for list, and for detail
|
||||
"""
|
||||
|
||||
Document.objects.create(
|
||||
@ -114,6 +114,7 @@ class TestApiObjects(DirectoriesMixin, APITestCase):
|
||||
checksum="456",
|
||||
)
|
||||
|
||||
# Only if requested for list
|
||||
response = self.client.get(
|
||||
"/api/correspondents/",
|
||||
)
|
||||
@ -131,6 +132,16 @@ class TestApiObjects(DirectoriesMixin, APITestCase):
|
||||
results[0]["last_correspondence"],
|
||||
)
|
||||
|
||||
# Included in detail by default
|
||||
response = self.client.get(
|
||||
f"/api/correspondents/{self.c1.id}/",
|
||||
)
|
||||
self.assertEqual(response.status_code, status.HTTP_200_OK)
|
||||
self.assertIn(
|
||||
"2022-01-02",
|
||||
response.data["last_correspondence"],
|
||||
)
|
||||
|
||||
|
||||
class TestApiStoragePaths(DirectoriesMixin, APITestCase):
|
||||
ENDPOINT = "/api/storage_paths/"
|
||||
|
@ -279,6 +279,12 @@ class CorrespondentViewSet(ModelViewSet, PermissionsAwareDocumentCountMixin):
|
||||
)
|
||||
return super().list(request, *args, **kwargs)
|
||||
|
||||
def retrieve(self, request, *args, **kwargs):
|
||||
self.queryset = self.queryset.annotate(
|
||||
last_correspondence=Max("documents__created"),
|
||||
)
|
||||
return super().retrieve(request, *args, **kwargs)
|
||||
|
||||
|
||||
class TagViewSet(ModelViewSet, PermissionsAwareDocumentCountMixin):
|
||||
model = Tag
|
||||
|
Loading…
x
Reference in New Issue
Block a user