November 2015
Beginner to intermediate
840 pages
26h 30m
English
The User model is rather unusual, because you’re not supposed to interact with it as you do with other Django models. Specifically, you should never import it directly, as is done in Example 19.10, for reasons we’ll see in Chapter 22.
Example 19.10: Python Code
# this is not the best way to do this! >>> from django.contrib.auth.models import User
Instead, developers should use the get_user_model() function supplied by auth to get the User model, as shown in Example 19.11.
Example 19.11: Python Code
# optimal >>> from django.contrib.auth import get_user_model >>> SiteUser = get_user_model() >>> SiteUser <class 'django .contrib.auth.models.User'> >>> User
Read now
Unlock full access