I inherited a system which has one User model, and a Profile model that is 
1-to-1 with User.  The type-of-user information is carried in a required 
"role" property in the Profile.  I think that is a well-established 
approach.

I am curious to hear what people think of the tradeoffs between (User + 
Profile) and (User-base-class + subclasses).

On Tuesday, May 15, 2018 at 12:41:50 PM UTC-4, Vijay Khemlani wrote:
>
> I would make a UserType table and have a foreign key from your user model 
> to it, or maybe just have an enumerated type in your user model depending 
> on how much custom logic there is to each user type.
>
> On Tue, May 15, 2018 at 11:50 AM Frankline <frao...@gmail.com 
> <javascript:>> wrote:
>
>> Hello Everyone,
>>
>> I am developing an API based on Django Rest Framework 
>> <http://www.django-rest-framework.org/>. Currently I have 4 user types 
>> i.e. Buyer, Merchant, Insurer, and Admin.
>>
>> The system I'm developing has an *API endpoint* and a *Dashboard* view.
>>
>> Each of the above user types have different fields and may need to login 
>> to the system at one point, so having one user model is the best way to go. 
>> Note that, a user can only be of one type.
>>
>> However, only the merchant will be actively using the API endpoint.
>>
>> My question is then, how will I be able to manage the different user 
>> types in the system?
>>
>> My current options are:
>>
>> 1.
>>
>>    1. class BaseUser(AbstractBaseUser):
>>    2. ...
>>    3.  
>>    4. class Buyer(BaseUser):
>>    5. ...
>>    6. 
>>    
>>
>>    1. class Merchant(BaseUser):
>>    2. ...
>>    3. 
>>    
>>
>>    1. class Insurer(BaseUser):
>>    2. ...
>>
>>
>> 2. 
>>
>>
>>    1. from django.db import models
>>    2. from django.contrib.auth.models import User
>>    3.  
>>    4. class Buyer(models.Model):
>>    5. user = models.OneToOneField(User)
>>    6.  
>>    7. class Merchant(models.Model):
>>    8. user = models.OneToOneField(User)
>>    9. 
>>    
>>
>>    1. class Insurer(models.Model):
>>    2. user = models.OneToOneField(User)
>>
>>
>>
>>    1. ...
>>
>>
>> Which is the most optimal way of handling this?
>>
>>    1. 
>>    
>>
>>
>>
>> -- 
>> You received this message because you are subscribed to the Google Groups 
>> "Django users" group.
>> To unsubscribe from this group and stop receiving emails from it, send an 
>> email to django-users...@googlegroups.com <javascript:>.
>> To post to this group, send email to django...@googlegroups.com 
>> <javascript:>.
>> Visit this group at https://groups.google.com/group/django-users.
>> To view this discussion on the web visit 
>> https://groups.google.com/d/msgid/django-users/CAEAUGdVwB_RrOP_s9Oj5fe6AoOXJ9qpPLUKpE%2BbAO_NLGMRn6g%40mail.gmail.com
>>  
>> <https://groups.google.com/d/msgid/django-users/CAEAUGdVwB_RrOP_s9Oj5fe6AoOXJ9qpPLUKpE%2BbAO_NLGMRn6g%40mail.gmail.com?utm_medium=email&utm_source=footer>
>> .
>> For more options, visit https://groups.google.com/d/optout.
>>
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/649bdc12-cf5a-4f01-8be6-7620854791d2%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to