Difference between AbstractUser and AbstractBaseUser in Django?

后端 未结 2 1035
说谎
说谎 2020-11-30 21:10

The use of AbstractUser and AbstractBaseUser looks quite similar.

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


        
相关标签:
2条回答
  • 2020-11-30 21:59

    The AbstractUser is basically just the "User" class you're probably already used to. AbstractBaseUser makes fewer assumptions and you have to tell it what field represents the username, what fields are required, and how to manage those users.

    If you're just adding things to the existing user (i.e. profile data with extra fields), then use AbstractUser because it's simpler and easier. If you want to rethink some of Django's assumptions about authentication, then AbstractBaseUser gives you the power to do so.

    0 讨论(0)
  • 2020-11-30 22:04

    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.

    0 讨论(0)
提交回复
热议问题