An important warning for updating solutions ... If you encounter such a problem, you probably tried various solutions on the Internet, suggesting you add AUTH_USER_MODEL = users.CustomUser to settings.py and then add the following code to views.py forms.py and any other file that calls User :
from django.contrib.auth import get_user_model User = get_user_model()
And then you scratch your head when you get an error:
Manager isn't available; 'auth.User' has been swapped for 'users.User'
At any time, your code refers to User such as:
User.objects.get()
Because you know that you have already placed objects = UserManager() in your user class ( UserManager is the name of your user manager extending BaseUserManager ).
Well, as it turns out (thanks @Aldarund):
User = get_user_model()
NOT equivalent:
get_user_model().objects.get()
It may not be intuitive, but it turns out that in python, executing User = get_user_model() once during the import does not cause User be defined on subsequent calls (that is, it does not turn User into a kind of "constant"). what can you expect if you come from C / C ++ background, which means that the execution of User = get_user_model() occurs during import, but then User = get_user_model() before the next User = get_user_model() class or function / method in this file )
Thus, to summarize, in all files that reference the User class (for example, calling functions or variables like User.objects.get() User.objects.all() User.DoesNotExist etc ...) :
Hope this helps save time for others ...
Janus source share