Hey all,
I'm trying to use Django's permission functionalities but having some trouble.
I've created a custom permission in one of my models with this code:
class Meta:
permissions = (
("actions_for_both_user_type", "General permission for both user types"),
("actions_for_managers", "managers general permission"),
)
I synced the DB and I can see the permissions in auth_permission table.
I entered the Django admin panel and chose a test user and gave him the 2 new permissions.
I've added a view that should be served only for a user with one of these permissions with this header:
@permission_required('campaign.actions_for_managers')
After login in with the user with the permissions I still can't get into the view.
If I take the permission_required head off and print these three lines
print request.user
print request.user.has_perm('campaign.actions_for_managers')
print request.user.user_permissions.all()
I'll see that I get the correct logged in user.
False for the second line (has_perm)
and for the third line I get this result:
[<Permission: campaign | campaign | General permission for both user types>, <Permission: campaign | campaign | managers general permission>]
I'm not sure what I'm doing wrong. It seems like the user does have the permission but the "had_perm" isn't working..
Please help.
Best