2

I am using Django's auth.

I want to distinguish between 3 types of users and present different content for each type of user.

How can I distinguish between these 3 types? Should I add a choice field specifying the type of user or create 3 groups and add the users to the right group?

How can I present different content according to the type of user?

Jamgreen
  • 10,329
  • 29
  • 113
  • 224

3 Answers3

2

Note that django.contrib.auth is primarily suited for authentication and authorization.

What you should do depends on what exactly type of user means.

In the typical situation where type represents different levels of authorizations the user has, then you should consider using the permission system (or running an existing one, see e.g. here).

If type represents an intrinsic property of the user (like male/female/other), then use a custom user and add a new ChoiceField to it.

If type represents something more complex, that potentially will have relations with other models, then I would go for a new model UserType.

Jorge Leitao
  • 19,085
  • 19
  • 85
  • 121
1

Create three different classes:

class Level1(models.model):
    member = models.ForeignKey(User)

class Level2(models.model):
    member = models.ForeignKey(User)

class Level3(models.model):
    member = models.ForeignKey(User)

To check and present different content for each user of different levels in the views:

if Level1.objects.filter(memeber=user).count() > 0:
    // present the content you want
else Level2.objects.filter(memeber=user).count() > 0:
    // present the content you want
else Level3.objects.filter(memeber=user).count() > 0:
    // present the content you want
Kakar
  • 5,354
  • 10
  • 55
  • 93
0

If you need to only assign different permissions to different type of user, go ahead and create an user group its pretty simple from django.contrib.auth.models import Group

newgroup = Group.objects.create(name=group_name)

The following answer will also help you setting permissions

User groups and permissions

Community
  • 1
  • 1
Aditya Pandhare
  • 501
  • 7
  • 16