Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save reyesvicente/cffe9786056590dd437975be9c0aeed2 to your computer and use it in GitHub Desktop.
Save reyesvicente/cffe9786056590dd437975be9c0aeed2 to your computer and use it in GitHub Desktop.
Django Rest Framework (DRF) Soft delete Mixin.
# in DRF DestroyModelMixin delete row. Using Same DELETE method I can soft delete object.
# ex: URL - DELETE https://<hostnam>/api/v1/books/1/
from rest_framework import mixins, permissions, viewsets
from rest_framework.response import Response
from rest_framework import status
class SlSoftDeleteMixin(mixins.DestroyModelMixin):
""" As we are deleting soft"""
def destroy(self, request, *args, **kwargs):
instance = self.queryset.get(id=kwargs.get('uuid'))
instance.is_active = False
instance.save()
return Response(status=status.HTTP_204_NO_CONTENT)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment