API reference

Form field and widget

Form widget and field.

PermissionSelectMultipleField
An optionnal form field purely for your own convenience.
PermissionSelectMultipleWidget
The actual permissions widget.
class permissions_widget.forms.PermissionSelectMultipleField(queryset=None, *args, **kwargs)[source]

Simple child of forms.ModelMultipleChoiceField which pre-sets queryset=Permission.objects.all(). It’s an optionnal item here for your convenience.

widget

alias of PermissionSelectMultipleWidget

class permissions_widget.forms.PermissionSelectMultipleWidget(attrs=None, choices=())[source]

Child of CheckboxSelectMultiple which renders permissions_widget/widget.html to display the form field.

Settings

Settings for permissions_widget.

EXCLUDE_APPS
The permissions widget will exclude any permission for any model in any app in the EXCLUDE_APPS list. It contains sensible defaults which you can override: sessions, admin and contenttypes for example, as in most cases users won’t even have the possibility of adding/changing/deleting sessions, logentries and content types so why even bother proposing permissions for them ? This would just confuse the admin. Can be overridden in settings.PERMISSIONS_WIDGET_EXCLUDE_APPS.
EXCLUDE_MODELS
The permissions widget will exclude any permission for any listed model. Models should be listed in the form of app.model. Can be overridden in settings.PERMISSIONS_WIDGET_EXCLUDE_MODELS.
PATCH_GROUPADMIN
If True, permissions_widget.admin will override the registered GroupAdmin form’s user_permission field to use this widget for permissions. Can be overridden (ie. to False) in settings.PERMISSIONS_WIDGET_PATCH_GROUPADMIN.
PATCH_USERADMIN
If True, permissions_widget.admin will override the registered UserAdmin form’s user_permission field to use this widget for permissions. Can be overridden (ie. to False) in settings.PERMISSIONS_WIDGET_PATCH_USERADMIN.

Admin form patch

Patch User and/or Group admin form to use the permission widget depending on settings.

The patch works like this:

  • get the user or group model,
  • get the registered ModelAdmin from admin.site for this model,
  • get the form of this ModelAdmin,
  • inherit from the form and replace the permissions field,
  • inherit from the modeladmin and replace the form,
  • unregister the model admin,
  • register the new inheriting model admin using the inheriting form with the permissions field override.

Project Versions

Table Of Contents

Previous topic

Welcome to django-permissions-widget’s documentation!

This Page