Admin — django-guardian v1.0.0.beta1 documentation

### Navigation

- index
- modules |
- next |
- previous |
- django-guardian v1.0.0.beta1 documentation »
- API Reference »

# Admin

## GuardedModelAdmin

class `guardian.admin.` `GuardedModelAdmin`(model, admin_site)

  Extends `django.contrib.admin.ModelAdmin` class. Provides some extra views for object permissions management at admin panel. It also changes default `change_form_template` option to `'admin/guardian/model/change_form.html'` which is required for proper url (object permissions related) being shown at the model pages.

  Extra options

  `GuardedModelAdmin.obj_perms_manage_template`

  > Default: `admin/guardian/model/obj_perms_manage.html`

  `GuardedModelAdmin.obj_perms_manage_user_template`

  > Default: `admin/guardian/model/obj_perms_manage_user.html`

  `GuardedModelAdmin.obj_perms_manage_group_template`

  > Default: `admin/guardian/model/obj_perms_manage_group.html`

  Usage example

  Just use `GuardedModelAdmin` instead of `django.contrib.admin.ModelAdmin`.

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

      class AuthorAdmin(GuardedModelAdmin):
          pass

      admin.site.register(Author, AuthorAdmin)

  `get_obj_perms_base_context`(request, obj)

    Returns context dictionary with common admin and object permissions related content.

  `get_obj_perms_manage_group_form`()

    Returns form class for group object permissions management. By default `AdminGroupObjectPermissionsForm` is returned.

  `get_obj_perms_manage_group_template`()

    Returns object permissions for group admin template. May be overridden if need to change it dynamically.

    Note

    If `INSTALLED_APPS` contains `grappelli` this function would return `"admin/guardian/grappelli/obj_perms_manage_group.html"`.

  `get_obj_perms_manage_template`()

    Returns main object permissions admin template. May be overridden if need to change it dynamically.

    Note

    If `INSTALLED_APPS` contains `grappelli` this function would return `"admin/guardian/grappelli/obj_perms_manage.html"`.

  `get_obj_perms_manage_user_form`()

    Returns form class for user object permissions management. By default `AdminUserObjectPermissionsForm` is returned.

  `get_obj_perms_manage_user_template`()

    Returns object permissions for user admin template. May be overridden if need to change it dynamically.

    Note

    If `INSTALLED_APPS` contains `grappelli` this function would return `"admin/guardian/grappelli/obj_perms_manage_user.html"`.

  `get_urls`()

    Extends standard admin model urls with the following:

    - `.../permissions/`
    - `.../permissions/user-manage/<user_id>/`
    - `.../permissions/group-manage/<group_id>/`

    Note

    `...` above are standard, instance detail url (i.e. `/admin/flatpages/1/`)

  `obj_perms_manage_group_view`(request, object_pk, group_id)

    Manages selected groups’ permissions for current object.

  `obj_perms_manage_user_view`(request, object_pk, user_id)

    Manages selected users’ permissions for current object.

  `obj_perms_manage_view`(request, object_pk)

    Main object permissions view. Presents all users and groups with any object permissions for the current model instance. Users or groups without object permissions for related instance would not be shown. In order to add or manage user or group one should use links or forms presented within the page.

### Navigation

- index
- modules |
- next |
- previous |
- django-guardian v1.0.0.beta1 documentation »
- API Reference »