Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Difference between AbstractUser and AbstractBaseUser in Django?

Tags:

python

django

The use of AbstractUser and AbstractBaseUser looks quite similar.

from django.contrib.auth.models import AbstractUser, AbstractBaseUser 

What is the difference between the two?

like image 276
Pranjal Mittal Avatar asked Feb 02 '14 18:02

Pranjal Mittal


People also ask

Should I use AbstractUser or AbstractBaseUser?

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.

What is settings Auth_user_model in Django?

Using settings. AUTH_USER_MODEL will delay the retrieval of the actual model class until all apps are loaded. get_user_model will attempt to retrieve the model class at the moment your app is imported the first time. get_user_model cannot guarantee that the User model is already loaded into the app cache.


1 Answers

The documentation explains this fully. AbstractUser is a full User model, complete with fields, as an abstract class so that you can inherit from it and add your own profile fields and methods. AbstractBaseUser only contains the authentication functionality, but no actual fields: you have to supply them when you subclass.

like image 127
Daniel Roseman Avatar answered Oct 18 '22 15:10

Daniel Roseman