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
GuardedModelAdmin.user_can_access_owned_objects_only
Default: False
If this would be set to True, request.user would be used to filter out objects he or she doesn’t own (checking user field of used model - field name may be overridden by user_owned_objects_field option).
Note
Please remember that this will NOT affect superusers! Admins would still see all items.
GuardedModelAdmin.user_can_access_owned_by_group_objects_only
Default: False
If this would be set to True, request.user would be used to filter out objects her or his group doesn’t own (checking if any group user belongs to is set as group field of the object; name of the field can be changed by overriding group_owned_objects_field).
Note
Please remember that this will NOT affect superusers! Admins would still see all items.
GuardedModelAdmin.group_owned_objects_field
Default: group
GuardedModelAdmin.include_object_permissions_urls
Default: True
New in version 1.2.
Might be set to False in order NOT to include guardian-specific urls.
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)