'Cannot set user.is_active to false
I have a custom user model and I am trying to deactive the user but it is not saving. There are also no error messages.
My model:
from django.contrib.auth.models import AbstractUser
from model_utils import FieldTracker
class User(AbstractUser):
# ... just some additional attributes
objects = UserManager()
tracker = FieldTracker()
u = User.objects.get(email="[email protected]")
u.is_active = False
u.save()
u.refresh_from_db()
u.is_active # Still returns True but should be False
Solution I found the reason why the save did not work is the Fieldtracker. Unfortunately, it is not mentioned in their documentation. The FieldTracker cannot handle the the attribute is_active=True of the base class. Workaround is to use FieldTracker to track specific fields (except is_active):
email_tracker = FieldTracker(fields=['email'])
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
