django-permissions-1.0 / docs / usage / simple.rst

Full commit



django-permissions is in alpha state. Please consider the API as supposed to be changed until it reaches beta state.

Create a new permission

from permissions.utils import register_permission
permission = register_permission("View", "view")

Create a new group

from permissions.utils import register_group
brights = register_group("Brights")

This will create a default Django group.

Create a content object

from django.contrib.flatpages.models import FlatPage
content = FlatPage.objects.create(title="Example", url="example")

Grant permission

from permission.utils import grant_permission
grant_permission("view", brights, content)

Now all users which are member of the group "Brights" have the permission to view object "content".


You can also grant permission to single users.

Check permission

from permission.utils import has_permission
result = has_permission("view", request.user, content)

if result == False:
    print "Alert!"

This will check whether the current user has the permission "View" for the FlatPage "content".