[Django]-Django REST overrride destroy method to make user inactive

3👍

If you want to make User as in active while keeping the UserInformation object and Userobject un-deleted in database, you can do something like this:

def destroy(self, request, *args, **kwargs):
    user = self.get_object().user
    user.is_active = False
    user.save()
    return Response(UserInformationUpdateSerializer(self.get_object()).data)
👤v1k45

0👍

You have 'is_active': {'read_only': True}}.

Also,

# this seems redundant
def delete(self, *args, **kwargs):
    self.user.delete()
    super(UserInformation, self).delete(*args, **kwargs)
👤Özer

Leave a comment