diff --git a/onadata/apps/api/tests/viewsets/test_attachment_viewset.py b/onadata/apps/api/tests/viewsets/test_attachment_viewset.py index 9bd021c498..60fa2c8ffa 100644 --- a/onadata/apps/api/tests/viewsets/test_attachment_viewset.py +++ b/onadata/apps/api/tests/viewsets/test_attachment_viewset.py @@ -230,7 +230,6 @@ def test_list_view_surfaces_current_attachment(self): # test when the attachment is soft deleted self.attachment.soft_delete(user=self.user) - self.attachment.save() request = self.factory.get('/', **self.extra) response = self.list_view(request) @@ -246,7 +245,7 @@ def test_soft_delete_action_returns_correct_user(self): # test when the attachment is soft deleted self.attachment.soft_delete(user=self.user) - self.attachment.save() + # Test that deleted_by field captures the right user self.assertTrue(self.attachment.deleted_by, self.user) diff --git a/onadata/apps/api/viewsets/attachment_viewset.py b/onadata/apps/api/viewsets/attachment_viewset.py index 3cc9ac05ee..af38671c40 100644 --- a/onadata/apps/api/viewsets/attachment_viewset.py +++ b/onadata/apps/api/viewsets/attachment_viewset.py @@ -47,7 +47,8 @@ class AttachmentViewSet(AuthenticateHeaderMixin, CacheControlMixin, ETagsMixin, content_negotiation_class = MediaFileContentNegotiation filter_backends = (filters.AttachmentFilter, filters.AttachmentTypeFilter) lookup_field = 'pk' - queryset = Attachment.objects.filter(instance__deleted_at__isnull=True) + queryset = Attachment.objects.filter( + instance__deleted_at__isnull=True, deleted_at__isnull=True) permission_classes = (AttachmentObjectPermissions,) serializer_class = AttachmentSerializer pagination_class = StandardPageNumberPagination @@ -100,9 +101,7 @@ def list(self, request, *args, **kwargs): if not xform.shared_data: raise Http404(_("Not Found")) - request_data = self.filter_queryset(self.get_queryset()) - self.object_list = self.object_list = [ - a for a in request_data if a.deleted_at is None] + self.object_list = self.filter_queryset(self.get_queryset()) page = self.paginate_queryset(self.object_list) if page is not None: serializer = self.get_serializer(page, many=True)