-4👍
You might as well use a completely custom user that inherits from AbstractUser. That has exactly the same functionality as what you’re trying here.
5👍
Setting AUTH_USER_MODEL
to a custom class, and using a proxy model are two different approaches to customizing Django’s User model behaviour. You’re seeing that error because you’re mixing them together, which doesn’t make sense.
Approach 1:
If you set AUTH_USER_MODEL='myapp.CustomUser'
then you shouldn’t proxy anything. Define your custom user model like so:
from django.contrib.auth.models import AbstractUser
class CustomUser(AbstractUser):
pass
Approach 2:
Proxy the Django user model as you have above. Don’t set AUTH_USER_MODEL
. In your code, make sure you’re always importing and using your CustomUser class.
Between the two approaches, #2 is preferred if you’re starting a new project because it gives you the most control. However, if you already have a running project migrating to a different model is a little tricky and so approach #1 with a proxy might be the best you can do.
See https://docs.djangoproject.com/en/3.2/topics/auth/customizing/#extending-the-existing-user-model for more details.
- How do I run periodic tasks with celery beat?
- Single sign on to Django site via remote Active Directory
- How to limit a <td> to only three lines?