User authentication and authorization are mission-critical for web platforms. While Django ships with a default User model, production architectures strongly advise configuring a Custom User Model at the inception of a project. This allows you to use email addresses as unique login identifiers, add custom enterprise fields, and manage fine-grained permissions.
Django's default auth.User uses username for logins and has fixed fields (first_name, last_name, email). Altering the user model mid-project requires complex, risky database migrations across foreign keys.
By defining a custom user model inheriting from AbstractUser on Day 1, you preserve total freedom to extend user attributes throughout the application lifetime:
AUTH_USER_MODEL in SettingsInform Django to use your custom model globally:
When referencing the user model across your codebase:
models.py foreign keys: use settings.AUTH_USER_MODELget_user_model()Django models automatically generate four default permissions upon creation:
add_<modelname> (e.g. articles.add_article)change_<modelname> (e.g. articles.change_article)delete_<modelname> (e.g. articles.delete_article)view_<modelname> (e.g. articles.view_article)@permission_requiredContinue learning with hands-on practice, examples, and exercises in the upcoming topic.
| Previous Lesson | Next Lesson |
|---|---|
| Django Admin Site | Groups and Roles |
Test your understanding of this lesson with 5 questions. Each question has one correct answer.
Practice in live mentor-led sessions with real projects, mock tests, and verifiable certification at MSK Institute.