Answer the question
In order to leave comments, you need to log in
Problem with django-guardian?
My project uses per-object permissions.
For this I use django-guardian
Everything is fine, but the get_objects_for_user() function does not work
qs - some queryset
my_usr - some user
In [1]: qs
Out[1]: [<SomeModel: obj1>, <SomeModel: obj2>]
In [2]: my_usr.has_perm('somename.change_somemodel', qs[0])
Out[2]: True
In [3]: my_usr.has_perm('somename.change_somemodel', qs[1])
Out[3]: False
In [4]: get_objects_for_user(my_usr, 'somename.change_somemodel', qs)
Out[4]: [<SomeModel: obj1>, <SomeModel: obj2>]
In [5]: [x for x in qs if my_usr.has_perm('somename.change_somemodel', x)]
Out[5]: [<SomeModel: obj1>]
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question