[Answered ]-Understanding guardian.shortcuts.get_objects_for_user

2👍

Use it like this:
news = get_objects_for_user(u, (‘change_news’), klass=News)

Edit:
Well, its easy to figure out where the problem is : try using guardian.shortcuts.get_perms (http://pythonhosted.org/django-guardian/api/guardian.shortcuts.html#get-perms) to see if permission between user and object really exists. I ran into similar issue some time ago and if i remember correctly, then it had something to do with user beeing superuser. Try setting is_superuser false for the user and see if has_perm still returns true.

Also, if possible, i suggest you don’t use get_objects_for_user shortcut when project gets bigger. Its VERY slow query once you get more objects/permissions in the database.

Alan

Leave a comment