Hi James,

     Correct me if I am wrong but if I understood you correctly, I should 
be able to implement it this way -

class User(AbstractBaseUser, PermissionsMixin):
    common_fields_go_her = ...

    objects = CustomUserManager()
    class Meta:
        abstract = True


class Customer(User):
    customer_specific_fields = ...


class Merchant(User):
    merchant_speicifc_fields = ...

In this case, what would be AUTH_USER_MODEL? If i am not wrong, an abstract 
base class cannot be an AUTH_USER_MODEL.


On Monday, August 10, 2015 at 11:20:43 PM UTC+5:30, James Schneider wrote:

> That is an incorrect assumption. Abstract model classes do not generate 
> any database tables, and are specifically designed for inheritance purposes 
> (otherwise they are pretty much useless). It is impossible for a OneToOne 
> field to exist that points to an abstract class.
>
>
> https://docs.djangoproject.com/en/1.8/topics/db/models/#abstract-base-classes
>
> If you need a similar example, look at how Django defines its own User 
> class:
>
>
> https://github.com/django/django/blob/1.8.3/django/contrib/auth/models.py#L436
>
> User inherits from AbstractUser (abstract class that adds 
> username/password fields, etc.), which in turn inherits from 
> AbstractBaseUser (abstract class that adds other methods for grabbing 
> various attributes of a User object). There are no excessive joins created 
> by queries against the User class because both AbstractUser and 
> AbstractBaseUser are both...abstract. They don't exist in the DB. 
>
> -James
>
> On Mon, Aug 10, 2015 at 10:29 AM, Ankit Agrawal <aaaag...@gmail.com 
> <javascript:>> wrote:
>
>> @James: Even if I implement a Custom abstract class inheriting from 
>> AbstractBaseUser, the Custom Abstract Class would have a explicit 
>> OneToOneField to the AbstractBaseUser, which essentially would mean having 
>> overheads due to JOINs as in MTI.
>>
>>
>> Ankit Agrawal,
>> IIT Bombay.
>>
>> On Mon, Aug 10, 2015 at 10:17 PM, James Schneider <jrschn...@gmail.com 
>> <javascript:>> wrote:
>>
>>> If you want to avoid MT inheritance, look at inheriting from 
>>> AbstractBaseUser using a custom abstract class where you can add your extra 
>>> custom fields. Your two types of users (inheriting from your new abstract 
>>> class) would then be standard, separate models.
>>>
>>> -James
>>> On Aug 10, 2015 9:24 AM, "Robin Lery" <robi...@gmail.com <javascript:>> 
>>> wrote:
>>>
>>>> You surely can use Choice field for either Customer or Merchant in your 
>>>> custom user class.
>>>> On 10 Aug 2015 20:12, "Avraham Serour" <tov...@gmail.com <javascript:>> 
>>>> wrote:
>>>>
>>>>> I personally like a profile model, but if you implement two you may 
>>>>> have headaches when doing a reverse relation from user, you would need to 
>>>>> check every time of the request.user is a customer or merchant.
>>>>>
>>>>> In any case what is the difference between them anyway? Why can't a 
>>>>> user be both?
>>>>>
>>>>> On Mon, Aug 10, 2015, 4:38 PM Ankit Agrawal <aaaag...@gmail.com 
>>>>> <javascript:>> wrote:
>>>>>
>>>>>> I am working on a project which has two different sets of users - 
>>>>>> Customer and Merchant. Both of these users should be able to 
>>>>>> register and login to their respective profiles. The most obvious choice 
>>>>>> to 
>>>>>> implement this that came to my mind was to make two different models 
>>>>>> Customer and Merchant that inherit from a BaseUser model that will 
>>>>>> store the common fields i.e. Multi-table inheritance - 
>>>>>> https://docs.djangoproject.com/en/1.8/topics/db/models/#multi-table-inheritance
>>>>>>
>>>>>>
>>>>>> Quoting Two Scoops of Django -
>>>>>>
>>>>>>
>>>>>> At all costs, everyone should avoid multi-table inheritance (see warning 
>>>>>> above) since it adds both confusion and substantial overhead...Adds 
>>>>>> substantial overhead since each query on a child table requires joins 
>>>>>> with all parent tables.
>>>>>>
>>>>>> I would like to know if and why having an explicit OneToOneField is 
>>>>>> better than Multi-table inheritance. Also, are there any other better 
>>>>>> ways 
>>>>>> to model the above relationship?
>>>>>>
>>>>>> -- 
>>>>>> 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 http://groups.google.com/group/django-users.
>>>>>> To view this discussion on the web visit 
>>>>>> https://groups.google.com/d/msgid/django-users/81954b62-2c89-404f-94a5-5f9a485c28c8%40googlegroups.com
>>>>>>  
>>>>>> <https://groups.google.com/d/msgid/django-users/81954b62-2c89-404f-94a5-5f9a485c28c8%40googlegroups.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...@googlegroups.com <javascript:>.
>>>>> To post to this group, send email to django...@googlegroups.com 
>>>>> <javascript:>.
>>>>> Visit this group at http://groups.google.com/group/django-users.
>>>>> To view this discussion on the web visit 
>>>>> https://groups.google.com/d/msgid/django-users/CAFWa6tJar_3PcyOytTsY1EKhbW4Y7M45Kqnt4oU3VLyvGjfrEw%40mail.gmail.com
>>>>>  
>>>>> <https://groups.google.com/d/msgid/django-users/CAFWa6tJar_3PcyOytTsY1EKhbW4Y7M45Kqnt4oU3VLyvGjfrEw%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...@googlegroups.com <javascript:>.
>>>> To post to this group, send email to django...@googlegroups.com 
>>>> <javascript:>.
>>>> Visit this group at http://groups.google.com/group/django-users.
>>>> To view this discussion on the web visit 
>>>> https://groups.google.com/d/msgid/django-users/CA%2B4-nGrDx8Aqiu6Xz%3Dwm_OMWgk_rC-kWBv_WGj%3DurWZNTE8LzA%40mail.gmail.com
>>>>  
>>>> <https://groups.google.com/d/msgid/django-users/CA%2B4-nGrDx8Aqiu6Xz%3Dwm_OMWgk_rC-kWBv_WGj%3DurWZNTE8LzA%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 a topic in the 
>>> Google Groups "Django users" group.
>>> To unsubscribe from this topic, visit 
>>> https://groups.google.com/d/topic/django-users/aV_PTRRD__s/unsubscribe.
>>> To unsubscribe from this group and all its topics, 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 http://groups.google.com/group/django-users.
>>> To view this discussion on the web visit 
>>> https://groups.google.com/d/msgid/django-users/CA%2Be%2BciUUsqDvWwtNzkBuM-_Rg7YB6tFTDS7ShjCzHte%3Du5nvkA%40mail.gmail.com
>>>  
>>> <https://groups.google.com/d/msgid/django-users/CA%2Be%2BciUUsqDvWwtNzkBuM-_Rg7YB6tFTDS7ShjCzHte%3Du5nvkA%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...@googlegroups.com <javascript:>.
>> To post to this group, send email to django...@googlegroups.com 
>> <javascript:>.
>> Visit this group at http://groups.google.com/group/django-users.
>> To view this discussion on the web visit 
>> https://groups.google.com/d/msgid/django-users/CAON2ci%2B1xCAxqVpyJkn_UN3B_GTF1FUDCEdVJF1zym-QvWB9eA%40mail.gmail.com
>>  
>> <https://groups.google.com/d/msgid/django-users/CAON2ci%2B1xCAxqVpyJkn_UN3B_GTF1FUDCEdVJF1zym-QvWB9eA%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 http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/ce558793-2a1f-4626-918d-e046a911a1fc%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to