50π
β
had the same problem. I am guessing that at some point you have used a self-crafted AUTHENTICATION_BACKEND? Most examples on the net of this (INCLUDING THE DJANGO 1.0 DOCUMENTATION!) donβt mention that the Backends are responsible for permissions handling as well.
However, no biggie: In whatever backend file your code resides, include this import:
from django.contrib.auth.backends import ModelBackend
Then make sure the Backend you wrote extends ModelBackend, e.g.:
class EmailBackend(ModelBackend):
Should be fine.
π€Mark Henwood
1π
In my case it was because of permission caching. I get the user,
added permission to user.user_permissions
but user.get_all_permissions
was empty set()
and user.has_perm
was False
. This problem is only with shell not admin.
user = User.objects.get(username="User")
permission = Permission.objects.get(
codename="organizations.add_organization",
)
user.user_permissions.add(permission)
user.get_all_permissions() # set()
user.has_perm('organizations.add_organization') # False
I have to add additional line before checking permissions:
user.user_permissions.add(permission)
user = User.objects.get(username="User") # new
user.get_all_permissions()
π€nezort11
- [Django]-Django: Display Choice Value
- [Django]-Django β create a unique database constraint for 2 or more fields together
- [Django]-Celery β run different workers on one server
Source:stackexchange.com