skip to navigation
skip to content

Not Logged In

django-guardian 1.2.0

Implementation of per object permissions for Django 1.2 or later.

Package Documentation

Latest Version: 1.3

django-guardian is implementation of per object permissions [1] as authorization backend which is supported since Django 1.2. It won’t work with older Django releases.


Online documentation is available at


To install django-guardian simply run:

pip install django-guardian


We need to hook django-guardian into our project.

  1. Put guardian into your INSTALLED_APPS at settings module:

  2. Add extra authorization backend:

        'django.contrib.auth.backends.ModelBackend', # default
  3. Configure anonymous user ID



After installation and project hooks we can finally use object permissions with Django.

Lets start really quickly:

>>> jack = User.objects.create_user('jack', '', 'topsecretagentjack')
>>> admins = Group.objects.create(name='admins')
>>> jack.has_perm('change_group', admins)
>>> UserObjectPermission.objects.assign_perm('change_group', user=jack, obj=admins)
<UserObjectPermission: admins | jack | change_group>
>>> jack.has_perm('change_group', admins)

Of course our agent jack here would not be able to change_group globally:

>>> jack.has_perm('change_group')

Admin integration

Replace admin.ModelAdmin with GuardedModelAdmin for those models which should have object permissions support within admin panel.

For example:

from django.contrib import admin
from myapp.models import Author
from guardian.admin import GuardedModelAdmin

# Old way:
#class AuthorAdmin(admin.ModelAdmin):
#    pass

# With object permissions support
class AuthorAdmin(GuardedModelAdmin):
    pass, AuthorAdmin)
[1]Great paper about this feature is available at djangoadvent articles.
File Type Py Version Uploaded on Size
django-guardian-1.2.0.tar.gz (md5) Source 2014-03-07 279KB
  • Downloads (All Versions):
  • 1044 downloads in the last day
  • 6186 downloads in the last week
  • 26675 downloads in the last month