Hi guys,
I've been trying the whole day to use django-registration with a custom user model.
Basically this is what I did :
1/ Create a custom user model (models.py)
class customUser(AbstractUser):
company_name = models.CharField(max_length=255)
--> My first question is do I need to add "objects = UserManager()" to my model ?
2/ Register my new user in the admin interface
from django.contrib import admin
from django.contrib.auth.models import Group
from .models import customUser
admin.site.register(customUser)
3/ Add my customUser to my settings.py
AUTH_USER_MODEL = 'myApp.customUser'
Ok from this point everything works fine !
But my next step was to use django-registration [1] to have a full user creation workflow.
After the installation, when I've tried to register a new user using the registration forms, Django raised this error:
django Manager isn't available; User has been swapped
I've tried different things but none of them have worked.
The only solution I found [2] is by modifying directly django-registration:
Edit registration/forms.py, in the top change
from django.contrib.auth.models import User
to
from django.contrib.auth import get_user_model
User = get_user_model()
While I really don't like to change an existing application, after this change I was able to use both django-registration and my custom user.
So I'm sure you can guess my question, is there no other way to do this ? I really would like to keep my code clean without this kind of dirty hack.
Thanks
Arnaud