What is the difference between these two and what is the purpose of AbstractBaseUser when I can give any field to User model? 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()
AbstractUser subclasses the User model. So that single model will have the native User fields, plus the fields that you define.
Where as assigning a field to equal User i.e. user=models.ForeignKey(User) is creating a join from one model to the User model.
You can use either one, but the recommended way for django is to create a join, so using => user=models.ForeignKey(User)
The correct model to sublclass is django.contrib.auth.models.AbstractUser as noted here in the docs:
https://docs.djangoproject.com/en/1.6/topics/auth/customizing/#extending-django-s-default-user
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