[Answered ]-Extending django User model using Django-mppt

1👍

Django documentation: Customizing authentication in Django recommends the following options :

There are two ways to extend the default User model without substituting your own model. If the changes you need are purely behavioral, and don’t require any change to what is stored in the database, you can create a proxy model based on User. This allows for any of the features offered by proxy models including default ordering, custom managers, or custom model methods.

If you wish to store information related to User, you can use a one-to-one relationship to a model containing the fields for additional information. This one-to-one model is often called a profile model, as it might store non-auth related information about a site user.

Some kinds of projects may have authentication requirements for which Django’s built-in User model is not always appropriate. For instance, on some sites it makes more sense to use an email address as your identification token instead of a username.

Both of the above may inherit from MPTTModel and solve your problem. I would personally recommend the first approach as being simpler, and it sounds to me that it will be enough for what you describe, but that again depends on your particular future requirements.

👤Wtower

1👍

I think what you are describing are actually 2 different issues.
Your company model needs to be hierarchical but that does not mean that the User model needs to be as well.
You would probably have:

class Company(<mpttmodel>):
    pass

class YourUser(User):
    company = models.ForeignKey(null=True)

Otherwise, if YourUser is inheriting frm mptt model you will have your user model hierarchical instead of the company model.

👤chaos

Leave a comment