About Lesson
By default, Django uses a basic User
model for authentication. However, in some projects, you may need to extend or replace the default User
model to meet specific needs, such as adding custom fields.
Extending the User Model
To extend the user model without replacing it, you can subclass AbstractUser
and add custom fields.
Example of Extending the Default User Model:
After creating a custom user model, set it in settings.py
:
AUTH_USER_MODEL = 'myapp.CustomUser'
Replacing the Default User Model
If you need to completely replace the default User
model, you can create a custom model that subclasses AbstractBaseUser
.
Example of a Custom User Model:
Join the conversation