Creating custom user model using AbstractUser in django_Restframework
Every new Django project should use a custom user model. The official Django documentation says it is “highly recommended” but I’ll go a step further and say without hesitation: You are straight up crazy not to use a custom user model up front.
Why do u need a custom user model in Django?
When you start your project with a custom user model, stop to consider if this is the right choice for your project.
Keeping all user related information in one model removes the need for additional or more complex database queries to retrieve related models. On the other hand, it may be more suitable to store app-specific user information in a model that has a relation with your custom user model. That allows each app to specify its own user data requirements without potentially conflicting or breaking assumptions by other apps. It also means that you would keep your user model as simple as possible, focused on authentication, and following the minimum requirements Django expects custom user models to meet.
So i think its clear why we need a custom user model in django, here in this article we are going to learn how to create custom user model and its api in django now
Steps to create Custom User Model
$ cd ~/Desktop$ mkdir code && cd code
$ pipenv install django
Make a new Django project called login
$ django-admin startproject login
$ python manage.py startapp api $ pipenv install rest_framework
$ python manage.py makemigrations users $ python manage.py migrate
$ python manage.py createsuperuser Email address: firstname.lastname@example.org Password: Password (again): Superuser created successfully.
$ python manage.py runserver
Attention geek! Strengthen your foundations with the Python Programming Foundation Course and learn the basics.
To begin with, your interview preparations Enhance your Data Structures concepts with the Python DS Course. And to begin with your Machine Learning Journey, join the Machine Learning – Basic Level Course