One way around is to make the models Employee and Company to inheret from
User in models.py


class Employee(User):
 ...

class Company(User):
 ...




On Sun, 24 Nov 2019, 5:33 am Underground Creatorz, <
moorestephen...@gmail.com> wrote:

> Hello all. Have a merry christmas and happy new Year. (
> moorestephen...@gmail.com)
>
> On Sat., 23 Nov. 2019, 11:26 am Elic, <elic...@gmail.com> wrote:
>
>> Hi,
>>
>> Hope you are all doing well.
>>
>> I had to change the User object to support several use-cases in my system.
>>
>> I have created a custom User object that extends AbstractBaseUser.This
>> object only has email, password, last_login and the permissions (is_stuff,
>> is_superuser). I also created UserManager for it.
>>
>> If I go to the /admin I can create new users and it works well.
>>
>> However, I have to extends this user, to allow different kind of users:
>>
>> 1. Company
>> 2. Employee
>>
>> In both cases I hold a onetoone User object reference:
>>
>> class Employee(models.Model):
>>
>>     user = models.OneToOneField(User, on_delete=models.CASCADE, 
>> related_name='+')
>>
>>
>> I read documentation and found places that describe how to add inline
>> nesting in the admin UI, however, in all the scenarios I saw it shows that
>> the inline is done on the User object which then adds part for an Employee.
>>
>> However, this is not what I want. I would like to enable creating a user
>> via /admin only when creating a Company or Employee.
>>
>> For Example when I want to create an Employee I will have the following
>> fields:
>> - email
>> - password
>> (these 2 come from the User)
>>
>> - name
>> - birthday
>> (these are coming from the Employee)
>>
>> Is it possible to achieve?
>>
>> Thank you,
>> Elic
>>
>> --
>> 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 view this discussion on the web visit
>> https://groups.google.com/d/msgid/django-users/bc0222b2-c46d-4d59-9028-f8057d7ad9c6%40googlegroups.com
>> <https://groups.google.com/d/msgid/django-users/bc0222b2-c46d-4d59-9028-f8057d7ad9c6%40googlegroups.com?utm_medium=email&utm_source=footer>
>> .
>>
> --
> 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 view this discussion on the web visit
> https://groups.google.com/d/msgid/django-users/CAEEmsyYAHgFFrT%3DuosahDSe7rSVNdDGevYNJ4b_g1Qa-iruYXg%40mail.gmail.com
> <https://groups.google.com/d/msgid/django-users/CAEEmsyYAHgFFrT%3DuosahDSe7rSVNdDGevYNJ4b_g1Qa-iruYXg%40mail.gmail.com?utm_medium=email&utm_source=footer>
> .
>

-- 
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 view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CAHV4E-dH0NNSgZDY5zi1Xy5Zv7jPAZMtmnPGSQNekvVhFHi14Q%40mail.gmail.com.

Reply via email to