Bug? django.contrib.auth.forms using User model by importing from auth.models instead of get_user_model()

19 views
Skip to first unread message

Davor Lučić

unread,
Feb 22, 2017, 11:06:14 AM2/22/17
to django...@googlegroups.com
Hello,

I have issues using custom user model and forms from contrib.auth.forms
When using `UserCreationForm` it says `auth_user table does not exists` which is expected since i have different user model.

Looking at the code, some pieces of code use `get_user_model` and `UserModel` while model forms use `User` imported from `auth.models`.

For example:

https://github.com/django/django/blob/master/django/contrib/auth/forms.py#L10

If i use UserModel there it seems to work fine. Would this be considered a bug? 
Just wanted to check before creating a ticket.

Thank you,
Davor


Tim Graham

unread,
Feb 22, 2017, 11:27:35 AM2/22/17
to Django users
The documentation says you need to rewrite UserCreationForm for a custom user model: https://docs.djangoproject.com/en/stable/topics/auth/customizing/#custom-users-and-the-built-in-auth-forms.

Davor Lučić

unread,
Feb 22, 2017, 11:39:58 AM2/22/17
to django...@googlegroups.com
Fair enough, I guess subclassing it makes more sense, I saw that it uses `USERNAME_FIELD`[1] so I assumed it could use the custom model by default too, but I guess you can have completely different models and that could create some confusion.

Anyway, sorry to take you time and thanks for quick response,
Reply all
Reply to author
Forward
0 new messages