When to use "AbstractBaseUser" in Django?
What is the difference between the two and what is the purpose of AbstractBaseUser
when I can give any field to the model User
? Which one is better to use with python-social-auth
?
class User(models.Model):
username = models.CharField(max_length=50)
is_active = models.BooleanField(default=True)
full_name = models.CharField(max_length=100)
date_of_birth = models.DateField()
and
class MyUser(AbstractBaseUser):
username = models.CharField(max_length=50)
is_active = models.BooleanField(default=True)
full_name = models.CharField(max_length=100)
date_of_birth = models.DateField()
source to share
AbstractUser
subclasses of the model User
. So one model will have its own User
fields, as well as the fields that you define.
Setting the field to User
ie user=models.ForeignKey(User)
creates a single model-to-model connection User
.
You can use any of these, but the recommended way for django is to create a connection, so use => user=models.ForeignKey(User)
Correct model for sublclass django.contrib.auth.models.AbstractUser
as stated here in the docs:
https://docs.djangoproject.com/en/1.6/topics/auth/customizing/#extending-django-s-default-user
source to share