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 8943603
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T11:48:58+00:00 2026-06-15T11:48:58+00:00

What is the recommended way to implement multiple user types using Django 1.5’s new

  • 0

What is the recommended way to implement multiple user types using Django 1.5’s new configurable user model functionality?

I would like to have two user types: private users and trade users, each with their own set of required fields.

There are two ways I can think to implement this:

1) Multi-table inheritance

class BaseUser(AbstractBaseUser):
  email = models.EmailField(max_length=254, unique=True)
  # ...


class PrivateUser(BaseUser):
  first_name = models.CharField(max_length=30)
  last_name = models.CharField(max_length=30)
  # ...


class TradeUser(BaseUser):
  company_name = models.CharField(max_length=100)
  # ...

Are there any problems with using multi-table inheritance in conjunction with the configurable user model?

2) Using a single model with a “type” attribute

class User(AbstractBaseUser):
  email = models.EmailField(max_length=254, unique=True)
  user_type = models.CharField(max_length=30, choices={
    'P': 'Private',
    'T': 'Trade',
  })
  first_name = models.CharField(max_length=30, blank=True)
  last_name = models.CharField(max_length=30, blank=True)
  company_name = models.CharField(max_length=100, blank=True)
  # ...

This method would require some conditional validation dependent upon user_type.

Which of these methods best suits my use case? Or perhaps there is a better way of achieving this?

Also, In case number 1, how can I filter my users?

Thanks.

  • 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-06-15T11:49:00+00:00Added an answer on June 15, 2026 at 11:49 am

    Warning: Django 1.5 is very new and the people are still investigating its new features. So my answer is nothing more than my opinion, based on recent research to answer this question.

    Both ways are valid ways to achieve the result, with its advantages and disadvantages.

    Let’s start with the:

    Second option

    • Without nested models and not modular. AbstractBaseUser, as the name says, is an abstract model and does not have a specific table
    • Has unused fields
    • You need to check the user_type for any iteration with the model that uses the extra fields:

      def foo():
          if user.user_type == 'Private':
              # ...
          else:
              # ...
      

    The resulting SQL would be approximately as follows:

    CREATE TABLE "myapp_user" (
        "id" integer NOT NULL PRIMARY KEY,
        "password" varchar(128) NOT NULL,
        "last_login" datetime NOT NULL,
        "email" varchar(254) NOT NULL UNIQUE,
        "user_type" varchar(30) NOT NULL,
        "first_name" varchar(30) NOT NULL,
        "last_name" varchar(30) NOT NULL,
        "company_name" varchar(100) NOT NULL
    );
    

    First option

    • Nested models with logical separation of entities
    • Very lean
    • You must implement BaseUserManager for each child if you want to use create_user-like functions
    • You cannot access the subclasses with a simple BaseUser.objects.all()*

    The resulting SQL would be approximately as follows:

    CREATE TABLE "myapp_baseuser" (
        "id" integer NOT NULL PRIMARY KEY,
        "password" varchar(128) NOT NULL,
        "last_login" datetime NOT NULL,
        "email" varchar(254) NOT NULL UNIQUE
    );
    
    CREATE TABLE "myapp_privateuser" (
        "baseuser_ptr_id" integer NOT NULL PRIMARY KEY REFERENCES "myapp_baseuser" ("id"),
        "first_name" varchar(30) NOT NULL,
        "last_name" varchar(30) NOT NULL
    );
    
    CREATE TABLE "myapp_tradeuser" (
        "baseuser_ptr_id" integer NOT NULL PRIMARY KEY REFERENCES "myapp_baseuser" ("id"),
        "company_name" varchar(100) NOT NULL
    );
    

    * Imagine the following situation:

    >>> BaseUser.objects.create_user('baseuser@users.com', password='baseuser')
    >>> PrivateUser.objects.create_user('privateuser@users.com', password='privateuser', first_name='His', last_name='Name')
    >>> TradeUser.objects.create_user('tradeuser@users.com', password='tradeuser', company_name='Tech Inc.')
    >>> BaseUser.objects.all()
    [<BaseUser: baseuser@users.com>, <BaseUser: privateuser@users.com>, <BaseUser: tradeuser@users.com>]
    >>> PrivateUser.objects.all()
    [<PrivateUser: privateuser@users.com>]
    >>> TradeUser.objects.all()
    [<TradeUser: tradeuser@users.com>]
    

    So, you cannot directly retrieve the subclasses instances by using BaseUser.objects.all(). There is an excellent blog post by Jeff explaining better how to accomplish “automatic downcast” from BaseUser to its childs.

    That said, you should consider the advantages and disadvantages of each approach and their impact on your project. When the involved logic is small (as in the example described), both approaches are valid. But in a more complex scenario, an approach can be better than the other one. I would choose the multi model option because it is more extensible.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Is there a recommended way of using Django to clean an input string without
What would be the easiest or recommended way for making an NSOutlineView indent multiple
I need some input.. What would be the best (well, recommended) way to implement
What is the recommended way to implement an announcments (or news) control in WPF?
What is recommended way to keep a user configuration data in Unix/Linux? My programming
I would appreciate if someone can point me the recommended ways of passing multiple
What is the recommended / best way to implement a blocking function call in
Is there any recommended way to do multiple string substitutions other than doing replace
The recommended way to handle optimistic locking in a RESTful interface seems to be
What is the recommended way of handling settings for local development and the production

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.