O'Reilly logo

Django Unleashed by Andrew Pinkham

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

19.5.1 User in the Shell

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

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required