0

Is my way of extending the auth.models.User of django correct? should I inherit from AbstractUser or User? Here is the way I am implementing it now: but should I consider having a OneToOneField connecting to the User table from UserProfile?

from django.contrib.auth.models import User

PHONE_LENGTH = 13
NAME_LENGTH = 100


###########################
### User Profile 
###########################
class UserProfile(User):
    """ inherits from AbstractUser in Django - mainly used for authentication"""
    # other fields here
    phone = models.CharField(max_length=PHONE_LENGTH)  #optional
    mobile = models.CharField(max_length=PHONE_LENGTH) #requried 

    # foreign key
    subscription_type = models.ForeignKey(SubscriptionType)

    def __str__(self):
        return "%s's profile" % self.user
Saher Ahwal
  • 9,015
  • 32
  • 84
  • 152

1 Answers1

2

you only inherit from AbstractUser when you need to change the existing User model that django provides and I don't see anything in your code that would need that.

other than that I don't think inheriting from User is a good idea. you should inherit from models.Model as usual and have a OneToOneField to User.

check this online book for more guidance : http://www.tangowithdjango.com/book/chapters/login.html

Lantern
  • 433
  • 3
  • 7