Note that there are some explanatory texts on larger screens.

plurals
  1. POImplementing multiple user types with Django 1.5
    primarykey
    data
    text
    <p>What is the recommended way to implement multiple user types using Django 1.5's new <a href="https://docs.djangoproject.com/en/dev/releases/1.5-beta-1/#configurable-user-model">configurable user model</a> functionality?</p> <p>I would like to have two user types: private users and trade users, each with their own set of required fields.</p> <p>There are two ways I can think to implement this:</p> <h2>1) Multi-table inheritance</h2> <pre><code>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) # ... </code></pre> <p>Are there any problems with using multi-table inheritance in conjunction with the configurable user model?</p> <h2>2) Using a single model with a "type" attribute</h2> <pre><code>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) # ... </code></pre> <p>This method would require some conditional validation dependent upon <code>user_type</code>.</p> <p>Which of these methods best suits my use case? Or perhaps there is a better way of achieving this?</p> <p>Also, In case number 1, how can I filter my users?</p> <p>Thanks.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload