Implementing multiple user types with Django 1.7

1,689 views
Skip to first unread message

marcelle Kouam

unread,
Jun 4, 2015, 4:58:15 PM6/4/15
to django...@googlegroups.com
hello,
I want to create differents types of user( manager, employee, client) in my model. but I don't know how to implemente this. I read many tutorials on the django site but I unable to implement this. thank for your help

this is my models.py


from django.db import models
from django.contrib.auth.models import User

# Create your models here.

class UserProfile(models.Model):
# This line is required. Links UserProfile to a User model instance.
user = models.OneToOneField(User)

# The additional attributes we wish to include.
website = models.URLField(blank=True)
picture = models.ImageField(upload_to='profile_images', blank=True)

# Override the __unicode__() method to return out something meaningful!
def __str__(self):
return self.user.username

class EmployeeProfile(models.Model):
# This line is required. Links UserProfile to a User model instance.
user = models.OneToOneField(UserProfile)

# The additional attributes we wish to include.

birthday = models.DateField()

# Override the __unicode__() method to return out something meaningful!
def __str__(self):
return self.user.username



how can


Andreas Kuhne

unread,
Jun 5, 2015, 5:24:35 AM6/5/15
to django...@googlegroups.com
Hi Marcelle,

You should not use the user profile solution anymore, because you can now create a custom User model instead. Check for example: http://www.lasolution.be/blog/creating-custom-user-model-django-16-part-1.html

This way you can add fields that are needed for your user solutions in your own user model. You can of course also add models that are specific for each type of user if you want.

Regards,

Andréas

--
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 http://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/1fbb0a3c-e0ea-48d2-b606-0c7db2bffb5d%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Daniel França

unread,
Jun 5, 2015, 5:31:19 AM6/5/15
to django...@googlegroups.com
You can define different groups for each role and assign the users to the groups.

marcelle Kouam

unread,
Jun 5, 2015, 10:51:58 AM6/5/15
to django...@googlegroups.com
thanks for your responses
I read the tutos that you have sended me andreas but it just implement one user.
but I want to have a structure which implements 3 types of users( handler, employee and client). can you give a clear example to do this.
thank for your help

Andreas Kuhne

unread,
Jun 5, 2015, 11:05:29 AM6/5/15
to django...@googlegroups.com
Hi again Marcelle,

It really depends on how you want to implement it. 

Here is one example which I think is pretty good: http://scopyleft.fr/blog/2013/django-model-advanced-user-inheritance/

This way you create a new model for each type you want (Handler, Employee and Client), and then you can check which kind of user it is.

Regards,

Andréas

Reply all
Reply to author
Forward
0 new messages