Skip to content

Django rest framework: how to make a view to delete multiple objects? #8356

Discussion options

You must be logged in to vote

You've already go the right approach in your SO question.

If you wanted the same sort of thing, but based on the generic class based views, then you'd probably want something like this...

class ListOrBulkDelete(GenericAPIView):
    def get(self, request, *args, **kwargs):
        queryset = self.filter_queryset(self.get_queryset())
        serializer = self.get_serializer(queryset, many=True)
        return Response(serializer.data)

    def delete(self, request, *args, **kwargs):
        queryset = self.filter_queryset(self.get_queryset())
        queryset.delete()  # CAREFUL! This could easily delete all the items in this queryset.
                                       # You might want…

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@abubakarsohail
Comment options

Answer selected by auvipy
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
3 participants