Per site permissions in django admin
Switch branches/tags
Nothing to show
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Failed to load latest commit information.


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