Django User module extend

26 views
Skip to first unread message

Ketul Suthar

unread,
Jan 5, 2018, 4:26:46 PM1/5/18
to Django users
I am beginner to djnago.


I want to create app in which admin can create User and Manager and manager is assign to user ?

so how can i achieve ? For  that I have to extend user class bacause user and manager and admin all three can login in system

Jani Tiainen

unread,
Jan 5, 2018, 4:39:20 PM1/5/18
to django...@googlegroups.com
Hi,

There are numerous ways to achieve what you're asking for, I've been using following two:

You can (and if this a new project, should) create custom user, regardless of which one approaches you use.

1) For a custom manager add user type field to a custom user model which says is user a manager or ordinary user. And then add foreign key (or many to many if user can have multiple managers) to custom user model to self.

2)  Have so called "profile", a model with one to one relation to user model where you put all the same attributes as above.

Admin can work with both approaches, it's up to you to decide which one approach suits for you.

--
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+unsubscribe@googlegroups.com.
To post to this group, send email to django...@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/810439c8-6515-4dc6-808d-643b0f1e38d0%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.



--
Jani Tiainen

- Well planned is half done, and a half done has been sufficient before...

Ketul Suthar

unread,
Jan 5, 2018, 4:46:16 PM1/5/18
to django...@googlegroups.com

Ketul Suthar

unread,
Jan 5, 2018, 4:53:33 PM1/5/18
to django...@googlegroups.com
class Profile(models.Model):
user = models.OneToOneField(User, on_delete=models.CASCADE)
is_manager = models.BooleanField(default=False)
manager = models.ForeignKey(User,related_name='user_manager',on_delete=
models.CASCADE, blank=True,null=True)
def __str__(self): # __unicode__ for Python 2
return self.user.username

Is it right ? how can i create form ?
>>> email to django-users...@googlegroups.com.
>>> To post to this group, send email to django...@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/ms
>>> gid/django-users/810439c8-6515-4dc6-808d-643b0f1e38d0%40googlegroups.com
>>> <https://groups.google.com/d/msgid/django-users/810439c8-6515-4dc6-808d-643b0f1e38d0%40googlegroups.com?utm_medium=email&utm_source=footer>
>>> .
>>> For more options, visit https://groups.google.com/d/optout.
>>>
>>
>>
>>
>> --
>> Jani Tiainen
>>
>> - Well planned is half done, and a half done has been sufficient
>> before...
>>
>> --
>> 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.
>> To post to this group, send email to django...@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/CAHn91oeYGMRN0PcxPHUYtu1k8HheWFzwNru5FK%2BmcPZGOkCf8Q%
>> 40mail.gmail.com
>> <https://groups.google.com/d/msgid/django-users/CAHn91oeYGMRN0PcxPHUYtu1k8HheWFzwNru5FK%2BmcPZGOkCf8Q%40mail.gmail.com?utm_medium=email&utm_source=footer>
>> .

Matemática A3K

unread,
Jan 6, 2018, 7:40:17 AM1/6/18
to django...@googlegroups.com
On Fri, Jan 5, 2018 at 1:52 PM, Ketul Suthar <k2ls...@gmail.com> wrote:
class Profile(models.Model):
        user = models.OneToOneField(User, on_delete=models.CASCADE)
        is_manager  = models.BooleanField(default=False)
        manager = models.ForeignKey(User,related_name='user_manager',on_delete=
models.CASCADE, blank=True,null=True)
        def __str__(self):  # __unicode__ for Python 2
                return self.user.username

Is it right ?

Seems so

how can i create form ?


>>> To post to this group, send email to django...@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/ms
>>> gid/django-users/810439c8-6515-4dc6-808d-643b0f1e38d0%40googlegroups.com
>>> .
>>> For more options, visit https://groups.google.com/d/optout.
>>>
>>
>>
>>
>> --
>> Jani Tiainen
>>
>> - Well planned is half done, and a half done has been sufficient
>> before...
>>
>> --
>> 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

>> To post to this group, send email to django...@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/CAHn91oeYGMRN0PcxPHUYtu1k8HheWFzwNru5FK%2BmcPZGOkCf8Q%
>> 40mail.gmail.com
>> .
>> 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+unsubscribe@googlegroups.com.

To post to this group, send email to django...@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
Reply all
Reply to author
Forward
0 new messages