|
4 | 4 | Handling permissions using Django's admin interface
|
5 | 5 | ===================================================
|
6 | 6 |
|
7 |
| -*to be written* |
| 7 | +*to be written* |
| 8 | + |
| 9 | +Apply permissions using Django's admin actions |
| 10 | +============================================== |
| 11 | + |
| 12 | +.. note:: Django admin actions are available in Django 1.1 or later. |
| 13 | + |
| 14 | +.. image:: .static/admin-action-permission.png |
| 15 | + |
| 16 | +Disable the admin action site-wide |
| 17 | +---------------------------------- |
| 18 | + |
| 19 | +To disable the action site-wide, place this line somewhere in your code. |
| 20 | +One of your app ``admin.py`` files might be a good place:: |
| 21 | + |
| 22 | + admin.site.disable_action('edit_permissions') |
| 23 | + |
| 24 | +Further informations are available in Django's documentation: |
| 25 | +`Disabling a site-wide action`_. If you encounter an error like:: |
| 26 | + |
| 27 | + Exception Type: KeyError at /admin/weblog/entry/ |
| 28 | + Exception Value: 'edit_permissions' |
| 29 | + |
| 30 | +Make sure you placed ``authority.autodiscover()`` before ``admin.autodiscover()``. |
| 31 | +See :ref:`configuration` for details. |
| 32 | + |
| 33 | +.. _Disabling a site-wide action: http://docs.djangoproject.com/en/dev/ref/contrib/admin/actions/#disabling-a-site-wide-action |
| 34 | + |
| 35 | +Disable the admin action per ModelAdmin instance |
| 36 | +------------------------------------------------ |
| 37 | + |
| 38 | +In case you want to disable the permission action per ModelAdmin, delete this |
| 39 | +action within the ``get_actions`` method. Here is an example:: |
| 40 | + |
| 41 | + class EntryAdmin(admin.ModelAdmin): |
| 42 | + |
| 43 | + def get_actions(self, request): |
| 44 | + actions = super(EntryAdmin, self).get_actions(request) |
| 45 | + del actions['edit_permissions'] |
| 46 | + return actions |
| 47 | + |
| 48 | +Further informations are available in Django's documentation: |
| 49 | +`Conditionally enabling or disabling actions`_. |
| 50 | + |
| 51 | +.. _Conditionally enabling or disabling actions: http://docs.djangoproject.com/en/dev/ref/contrib/admin/actions/#conditionally-enabling-or-disabling-actions |
0 commit comments