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


[1] https://django-registration.readthedocs.org/en/latest/#
[2] https://sulami.github.io/django-tweaking-custom-user-model-fixes.html

-- 
--------------------------------------------------------------------
Arnaud Vandecasteele
SIG - WebMapping - Spatial Ontology - GeoCollaboration

Web Site
http://www.marinegis.com/?page_id=131
http://geotribu.net/

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CAHZ2jmCiTF0wCcMcwHCc3muBuxwThyo6C0ivFPPEG80NknTW5g%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to