+ django-permissions is in alpha state. Please consider the API as supposed
+ to be changed until it reaches beta state.
+This will demonstrate how one can create special groups (per convention) and
+check permissions against them even if the user has not been assigned to these
+ from permissions.utils import register_permission
+ permission = register_permission("View", "view")
+ permission = register_permission("Edit", "edit")
+ from permissions.utils import register_group
+ anonymous = register_group("Anonymous")
+ owner = register_group("Owner")
+This will create default Django groups.
+ from django.contrib.flatpages.models import FlatPage
+ content = FlatPage.objects.create(title="Example", url="example")
+ from permission.utils import grant_permission
+ grant_permission("view", anonymous, content)
+ grant_permission("edit", owner, content)
+Now all users which are member of the special group "Anonymous" have the
+permission to view the object "content". And all users which are member of the
+special group "Owner" have the permission to edit the content.
+ from permission.utils import has_permission
+ from permission.utils import get_group
+ # Every user is automatically within the Anonymous group.
+ groups = [get_group("Anonymous")]
+ # The creator of the page is also within the Owner group.
+ # Note: FlatPages actually don't have a creator attribute.
+ if request.user == content.creator:
+ # Passing the additional groups to has_permission
+ result = has_permission("edit", request.user, content, groups)