Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 482123
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T01:03:52+00:00 2026-05-13T01:03:52+00:00

Hope all this makes sense :) I’ll clarify via comments if necessary. Also, I

  • 0

Hope all this makes sense 🙂 I’ll clarify via comments if necessary. Also, I am experimenting using bold text in this question, and will edit it out if I (or you) find it distracting. With that out of the way…

Using django.contrib.auth gives us User and Group, among other useful things that I can’t do without (like basic messaging).

In my app I have several different types of users. A user can be of only one type. That would easily be handled by groups, with a little extra care. However, these different users are related to each other in hierarchies / relationships.

Let’s take a look at these users: –

Principals – “top level” users

Administrators – each administrator reports to a Principal

Coordinators – each coordinator reports to an Administrator

Apart from these there are other user types that are not directly related, but may get related later on. For example, “Company” is another type of user, and can have various “Products”, and products may be supervised by a “Coordinator”. “Buyer” is another kind of user that may buy products.

Now all these users have various other attributes, some of which are common to all types of users and some of which are distinct only to one user type. For example, all types of users have to have an address. On the other hand, only the Principal user belongs to a “BranchOffice”.

Another point, which was stated above, is that a User can only ever be of one type.

The app also needs to keep track of who created and/or modified Principals, Administrators, Coordinators, Companies, Products etc. (So that’s two more links to the User model.)

In this scenario, is it a good idea to use Django’s multi-table inheritance as follows: –

from django.contrib.auth.models import User
class Principal(User):
    #
    #
    #    
    branchoffice = models.ForeignKey(BranchOffice)
    landline = models.CharField(blank=True, max_length=20)    
    mobile = models.CharField(blank=True, max_length=20)
    created_by = models.ForeignKey(User, editable=False, blank=True, related_name="principalcreator")    
    modified_by = models.ForeignKey(User, editable=False, blank=True, related_name="principalmodifier")
    #
    #
    #

Or should I go about doing it like this: –

class Principal(models.Model):
    #
    #
    #
    user = models.OneToOneField(User, blank=True)
    branchoffice = models.ForeignKey(BranchOffice)
    landline = models.CharField(blank=True, max_length=20)    
    mobile = models.CharField(blank=True, max_length=20)
    created_by = models.ForeignKey(User, editable=False, blank=True, related_name="principalcreator")    
    modified_by = models.ForeignKey(User, editable=False, blank=True, related_name="principalmodifier")
    #
    #
    #

Please keep in mind that there are other user types that are related via foreign keys, for example: –

class Administrator(models.Model):
    #
    #
    #
    principal = models.ForeignKey(Principal, help_text="The supervising principal for this Administrator")
    user = models.OneToOneField(User, blank=True)
    province = models.ForeignKey(         Province)
    landline = models.CharField(blank=True, max_length=20)    
    mobile = models.CharField(blank=True, max_length=20)
    created_by = models.ForeignKey(User, editable=False, blank=True, related_name="administratorcreator")    
    modified_by = models.ForeignKey(User, editable=False, blank=True, related_name="administratormodifier")

I am aware that Django does use a one-to-one relationship for multi-table inheritance behind the scenes. I am just not qualified enough to decide which is a more sound approach.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-13T01:03:52+00:00Added an answer on May 13, 2026 at 1:03 am

    I’d like to expand on the solution by @thornomad.

    Extending Django’s User class directly can cause all kinds of trouble with the internal django.auth mechanisms. What I’ve done in a similar situation is precisely what @thornomad suggests – I made my own UserProfile model linked one-to-one with the Django User model, in which I held additional user data and from which I inherited models for different types of users.

    Something to fit what you described:

    class UserProfile(models.Model):
        user = models.OneToOneField(User, blank=True, related_name='profile')
        class Meta:
            abstract = True
    
    
    class PositionHolderUserProfile(UserProfile):
        first_name = models.CharField(max_length=30)
        last_name = models.CharField(max_length=30)
        landline = models.CharField(blank=True, max_length=20)    
        mobile = models.CharField(blank=True, max_length=20)
        created_by = models.ForeignKey(PositionHolderUserProfile, editable=False, blank=True, related_name="created_users")    
        modified_by = models.ForeignKey(PositionHolderUserProfile, editable=False, blank=True, related_name="modified_users")
    
    class Principal(PositionHolderUserProfile):
        branchoffice = models.ForeignKey(BranchOffice)
    
    class Administrator(PositionHolderUserProfile):
        superior = models.ForeignKey(Principal, related_name="subordinates")
        province = models.ForeignKey(Province)
    
    class Coordinator(PositionHolderUserProfile):
        superior = models.ForeignKey(Administrator, related_name="subordinates")
    
    
    class Company(UserProfile):
        name = models.CharField(max_length=50)
    
    class Product(models.Model):
        name = models.CharField(max_length=50)
        produced_by = models.ForeignKey(Company)
    
    class Buyer(UserProfile):
        first_name = models.CharField(max_length=30)
        last_name = models.CharField(max_length=30)
        products_bought = models.ManyToManyField(Product)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm not a a very experienced Windows developer, so I hope this all makes
hope all is well. I am using Version 7.0. This morning I was struggling
I have an issue with jQuery and Safari (5.03). Hope this makes sense. I
Bit tricky to communicate but hope this makes sense. I have 8 div containers
First time here so I hope this makes sense! I have a Map which
I hope to list all files in document directory using codes below for(NSString *path
First of all, I hope you understand my English, because I'am not a native
Hope you're having a good Friday and stuff... okay, so here's my question: All
First of all, I am new to WPF and Xaml, so I just hope
Hope I'm asking this correctly: I have a project Projects.Client I have my class

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.