Per site permissions in django admin
Latest commit f888f8b May 30, 2011 @bmihelac fix typo in documentation
Failed to load latest commit information.
example typo fix May 30, 2011
site_permissions added May 30, 2011
README.rst fix typo in documentation May 30, 2011 added May 30, 2011


Site permissions

Site permissions django application allows restricting access to objects based on sites. Basic goal is to allow restricting managing site content to users and groups in django admin interface.

Sites permissions will add custom permission change_site_content to Site model. It depends on django-guardian.


  • django-guardian
  • Django 1.2 or later


Add site_permissions to INSTALLED_APPS:

    # Uncomment the next line to enable the admin:
    # Uncomment the next line to enable admin documentation:
    # 'django.contrib.admindocs',


In add authentication backends for guardian and site_permissions:

    'django.contrib.auth.backends.ModelBackend', # default backend
    'guardian.backends.ObjectPermissionBackend', # guardian
    "site_permissions.backends.SitePermissionBackend", # site_permissions

ANONYMOUS_USER_ID = -1 # required for guardian

Run syncdb to create permission for Site object:

./ syncdb

This will create Can change site content permission that affect in which sites specified user or group can edit contents.


  1. Add RestrictSiteMixin mixin to admin classes:

    from django.contrib import admin
    from site_permissions.backends import RestrictSiteMixin
    from models import Category
    class CategoryAdmin(RestrictSiteMixin, admin.ModelAdmin):
    , CategoryAdmin)
  2. In django admin set Can change site content object permissions for Site objects.

Example app

To test application and get a feeling how it works:

cd example
./ syncdb --noinput && ./ loaddata sample_data.json
./ runserver

Usernames are admin and user1. Password for all users is password.


  • add admin helper to filter foreign relationships within site
  • site field name should be configurable
  • handle many to many relationship to sites