Why use CustomUserManager.create_user and not CustomUserManager.create?

41 views
Skip to first unread message

Maarten Nieber

unread,
Feb 17, 2019, 1:05:41 PM2/17/19
to Django users
Hi,

the Django guidelines tell us to implement CustomUserManager.create_user. However, this seems to introduce some ambiguity between
CustomUserManager.create_user and CustomUserManager.create, since both these methods can be expected to create a User. In fact,
it would be easy to accidentically call the wrong method from source code.

Is there any reason why the create_user function exists at all? Why doesn't Django tell us to override CustomUserManager.create?

Or alternatively, I could imagine that Django could have a hook function that is called by CustomUserManager.create, where the hook can be used
to implemented custom behaviour (so that at least we have only 1 function to create users). Would this be a better design? Or is the current
design the correct one, and am I missing something? (in that case, please elaborate)

Best regards,
Maarten


Đảng Nguyễn Văn

unread,
Feb 18, 2019, 7:37:15 AM2/18/19
to django...@googlegroups.com

Vào 1:05, Th 2, 18 thg 2, 2019 Maarten Nieber <mni...@gmail.com đã viết:
--
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...@googlegroups.com.
To post to this group, send email to django...@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/b934b1a4-a295-4e83-be9c-b787785e5fc6%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Peter of the Norse

unread,
Mar 15, 2019, 12:48:11 AM3/15/19
to django...@googlegroups.com
The biggest difference is that when you call create_user, it creates a hash of the password.  Eventually, create_user does call create, but only after setting all the values properly.

Sent from my iPad

Vinicius Assef

unread,
Mar 19, 2019, 11:46:29 AM3/19/19
to django...@googlegroups.com
Also, there's the create_superuser() method.

Reply all
Reply to author
Forward
0 new messages