0

i have a django project that has 2 types of users ( teachers and students in my case )

i want each group of them to view a different page when they login. how is that possible ?

or how to know what group a certain user belong to ?

thanks in advance

Moayyad Yaghi
  • 3,622
  • 13
  • 51
  • 67

1 Answers1

1

To get the groups of a user check the docs on authentication.

User objects have two many-to-many fields: models.User. groups and user_permissions. User objects can access their related objects in the same way as any other Django model:

myuser.groups = [group_list]

So if you want to check if a user is member of the group teachers:

if myuser.groups.filter(name='teachers'):
    print "myuser is a teacher"
    ...

Considering the redirection see this answer: Django - after login, redirect user to his custom page --> mysite.com/username

Community
  • 1
  • 1
arie
  • 18,737
  • 5
  • 70
  • 76