21👍
✅
If you’re using a ModelViewSet, you could do it in the view:
class YourViewSetClass(ModelViewSet):
def destroy(self, request, *args, **kwargs):
user = request.user # deleting user
# you custom logic #
return super(YourViewSetClass, self).destroy(request, *args, **kwargs)
The destroy method is so simple (just a call to instance.delete()) that the action is not delegated to the serializer. The serializers in DRF are for negotiating external representations to/from your database models. Here you simply want to delete a model.
👤Rob
12👍
I think you can do that but in the view level.
So if you’re using ModelViewsets you can override the destory method or the perform_destroy
and add your business logic.
- No fixture named 'X' found
- Django Custom User Model errors ((admin.E108) The value of 'list_display[2]' refers to 'first_name', which is not a callable
Source:stackexchange.com