1
votes

I have an existing custom user model which I created based on the Django doc to have email-based authentication.

I want to extend the model to have multiple user types like Customers, Trainers, and Authors.

I am not sure how to go forward and what is the best way to extend this?

Also, have I made the right choice going with the AbstractBaseUser or should I have used the AbstractUser Class.

1
share your existing models, please!Abdul Rehman
@AbdulRehman I only have the accounts model right now with the custom right now with This is the code in my models.py with a few additional fields.Shady7447

1 Answers

1
votes

rename your MyUser class to MyUserBase or MyUserAbstract, then in this class

class MyUserBase(AbstractBaseUser):
  class Meta:
    abstract = True
  .
  .
  .

now you can extend it:

then recreate your MyUser class like this:

class MyUser(MyUserBase):
  pass

and the other models like this:

class Trainer(MyUserBase):
  ... #other properties

class Customer(MyUserBase):
  ... #other properties