Django-- Deactivate User account instead of deleting it

Viewed 10046

I want to deactivate the User account instead of deleting it. I want to do something like user.is_active = False. I have a view to delete User profile and it works but now I need to change it to only deactivate. Here is my view:

def delete_profile(request):
    user = User.objects.filter(id = request.user.profile.user_id)
    try:
        user.delete()
    except:
        messages.error(request,'Please try again.')
        return redirect('profile')

    messages.success(request, 'Profile successfully deleted.')
    return redirect('index')

I tried User.is_active = False , it displays the success message but doesn't do anything. When I check the User in admin panel it will still have User marked as active.

Any Idea how I can achieve this? Thanks in advance

4 Answers
Related