V
V
Vladimir Kuts2016-07-29 11:43:21
Django
Vladimir Kuts, 2016-07-29 11:43:21

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

Everything seems to be logical here. In the admin panel, I assigned the change_somemodel rights to only the first object
In [4]: get_objects_for_user(my_usr, 'somename.change_somemodel', qs)
Out[4]: [<SomeModel: obj1>, <SomeModel: obj2>]

Why does it output both objects? After all, he has no rights to the second one????
Z.Y. Such a crutch works as expected, but requires additional. performance costs):
In [5]: [x for x in qs if my_usr.has_perm('somename.change_somemodel', x)]
Out[5]: [<SomeModel: obj1>]

I would like the same behavior for the regular function get_objects_for_user

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question