This is a simple essay tutorial.
We use Django abstract class to create custom user modal. This is from official documents.
1. We have to create an app for account management.
2. In this, we import Django abstract class from Django in models.py file.
from django.contrib.auth.models import AbstractUser
3. Now we use this AbstractUser class in model class parameter like this.
4. Here we define our custom fields for user model
- First Name
- Last Name
- User Name
- Email
- Password
- Dob
5. After created this we tell Django to user this as Django default user model by adding it in setting.py file
Note - Here is app name first and then the model n
6. Now we can change our Django base user manager method with custom fields.
7. In this, we first import base user manager and create methods.
8. Now set this manager to our custom user model With
Objects = MyUserManager()
In this, we set the default user name authentication field to email or user name and email both.
9. Like this we user the Django custom user model.
10. By this, you can also use Django's other default features with the Django custom user model as well. for more reading go to Django official documents.
Comments
Post a Comment