Question

I am new to Django and I wanted to set privileges without using admin from my templates.

Was it helpful?

Solution

from https://docs.djangoproject.com/en/dev/topics/auth/#methods:

this is how to programatically add/remove permissions

myuser.groups = [group_list]
myuser.groups.add(group, group, ...)
myuser.groups.remove(group, group, ...)
myuser.groups.clear()

myuser.user_permissions = [permission_list]
myuser.user_permissions.add(permission, permission, ...)
myuser.user_permissions.remove(permission, permission, ...)
myuser.user_permissions.clear()
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top