AbstractUser vs AbstractBaseUser In Django (2024)

AbstractUser vs AbstractBaseUser In Django (1)

2 min read

·

Sep 28, 2021

--

AbstractUser vs AbstractBaseUser In Django (2)

It is important to understand the Difference between AbstractBaseUse and AbstractUser in Django, This Article will you to make the right decision on which one to use when you are starting a Django Project.

AbstractUser vs AbstractBaseUser In Django (3)

AbstractUser class inherits the User class and is used to add Additional Fields required for your User in Database itself. SO its change the schema of the database. It is basically used to add fields like date_of_birth , location and bio etc. to the existing User model This is Done to the very Beginning of the project. which means you will get the complete field which by default come with the user Model plus the following field that you add/define.

Example

AbstractUser vs AbstractBaseUser In Django (4)

in the above example you will get all the fields of the User model additionally the fields we defined here which are date_of_birth , address and bio_info .

AbstractBaseUser

AbstractBaseUser has the authentication functionality only , it has no actual fields you will supply the fields to use when you subclass.

you have to till that what field represent username fields, and how those users will be managed

for example you have to use email in your authentication , Normally Django use username in authentication, so how do you change it to use email?

AbstractUser vs AbstractBaseUser In Django (5)

If you need full control over User model, it is better to use AbstractBaseUser but if you are just adding things to the existing user, for example, you just want to add an extra field bio ,location field or any other profile data then use AbstractUser.

Thanks For Reading

AbstractUser vs AbstractBaseUser In Django (2024)
Top Articles
Latest Posts
Article information

Author: Rev. Porsche Oberbrunner

Last Updated:

Views: 5832

Rating: 4.2 / 5 (53 voted)

Reviews: 92% of readers found this page helpful

Author information

Name: Rev. Porsche Oberbrunner

Birthday: 1994-06-25

Address: Suite 153 582 Lubowitz Walks, Port Alfredoborough, IN 72879-2838

Phone: +128413562823324

Job: IT Strategist

Hobby: Video gaming, Basketball, Web surfing, Book restoration, Jogging, Shooting, Fishing

Introduction: My name is Rev. Porsche Oberbrunner, I am a zany, graceful, talented, witty, determined, shiny, enchanting person who loves writing and wants to share my knowledge and understanding with you.