The use of AbstractUser
and AbstractBaseUser
looks quite similar.
from django.contrib.auth.models import AbstractUser, AbstractBaseUser
What is the difference between the two?
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.
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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With