In django-guardian, how can I get all objects user has any permissions for -
In the Django-Guardian, how can I get all the objects user (even through groups) is one I am searching for all objects, there is no permission for a given user.
& gt; & Gt; & Gt; Guardian.shortcuts import_objects_for_user from import & gt; & Gt; & Gt; Joe = User.objects.get (user name = 'joe') & gt; & Gt; & Gt; Get_objects_for_user (which, 'auth.change_group') [] & gt; & Gt; & Gt; Import_perm & gt; from guardian.shortcuts & Gt; & Gt; Group = group.bizject Create ('some groups') & gt; & Gt; & Gt; Assign_param ('auth.change_group', Joe, group) & gt; & Gt; & Gt; You can write codenames in a list for any permission, or use [/ b>
.
& gt; & Gt; & Gt; Perm.codename] for perm in Group_perms = [perm.cperms_for_model (group)] gt; & Gt; & Gt; Get_objects_for_user (joe, group_perms, klass = group, any_perm = true) [& lt; Some group groups & gt;]
Comments
Post a Comment