django-permissions / docs / usage / simple_no_roles.rst

Simple Permission Management with Roles disabled

Create a new user

>>> from django.contrib.auth.models import User
>>> user = User.objects.create(username="doe")

Create a new permission

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

Create a content object

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

Grant permission

>>> from permissions.utils import grant_permission
>>> grant_permission(content, user, "view")

Now the user "doe" has the permission to view object "content".

Check permission

>>> from permissions.utils import has_permission
>>> has_permission(content, user, "view")

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

More information