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.