Tools for django admin
Project description
Django Admin Confirm
Features
- AdminConfirmMixin Based on django-admin-confirm with support for django-object-actions AdminConfirmMixin is a mixin for ModelAdmin to add confirmations to change, add and actions.
- AdminFormMixin AdminFormMixin is a mixin for ModelAdmin to add a form to configure your actions.
ScreenShot
Installation
Install django-admin-action-tools by running:
poetry add django-admin-action-tools
Add to INSTALLED_APPS in your project settings before django.contrib.admin
:
INSTALLED_APPS = [
...
'admin_action_tools',
'django.contrib.admin',
...
]
Note that this project follows the template override rules of Django.
To override a template, your app should be listed before admin_confirm
, admin_form
in INSTALLED_APPS.
Configuration Options
Environment Variables:
Caching is used to cache files for confirmation. When change/add is submitted on the ModelAdmin, if confirmation is required, files will be cached until all validations pass and confirmation is received.
ADMIN_CONFIRM_CACHE_TIMEOUT
default: 1000ADMIN_CONFIRM_CACHE_KEY_PREFIX
default: admin_confirm__file_cache
Attributes:
confirm_change
Optional[bool] - decides if changes should trigger confirmationconfirm_add
Optional[bool] - decides if additions should trigger confirmationconfirmation_fields
Optional[Array[string]] - sets which fields should trigger confirmation for add/change. For adding new instances, the field would only trigger a confirmation if it's set to a value that's not its default.change_confirmation_template
Optional[string] - path to custom html template to use for change/addaction_confirmation_template
Optional[string] - path to custom html template to use for actions
Note that setting confirmation_fields
without setting confirm_change
or confirm_add
would not trigger confirmation for change/add. Confirmations for actions does not use the confirmation_fields
option.
Method Overrides: If you want even more control over the confirmation, these methods can be overridden:
get_confirmation_fields(self, request: HttpRequest, obj: Optional[Object]) -> List[str]
render_change_confirmation(self, request: HttpRequest, context: dict) -> TemplateResponse
render_action_confirmation(self, request: HttpRequest, context: dict) -> TemplateResponse
Usage
AdminConfirmMixin
It can be configured to add a confirmation page on ModelAdmin upon:
- saving changes
- adding new instances
- performing actions
Confirm Change:
from admin_confirm import AdminConfirmMixin
class MyModelAdmin(AdminConfirmMixin, ModelAdmin):
confirm_change = True
confirmation_fields = ['field1', 'field2']
This would confirm changes on changes that include modifications onfield1
and/or field2
.
Confirm Add:
from admin_confirm import AdminConfirmMixin
class MyModelAdmin(AdminConfirmMixin, ModelAdmin):
confirm_add = True
confirmation_fields = ['field1', 'field2']
This would confirm add on adds that set field1
and/or field2
to a non default value.
Note: confirmation_fields
apply to both add/change confirmations.
Confirm Action:
from admin_confirm import AdminConfirmMixin
class MyModelAdmin(AdminConfirmMixin, ModelAdmin):
actions = ["action1", "action2"]
def action1(modeladmin, request, queryset):
# Do something with the queryset
@confirm_action
def action2(modeladmin, request, queryset):
# Do something with the queryset
action2.allowed_permissions = ('change',)
This would confirm action2
but not action1
.
Action confirmation will respect allowed_permissions
and the has_xxx_permission
methods.
Note: AdminConfirmMixin does not confirm any changes on inlines
AdminFormMixin
TODO
Development
Check out our development process if you're interested.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Hashes for django-admin-action-tools-0.1.0a1.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | 177922ec885bc523dba53df5075e59aebe9aaa5f8a82a76fe6ec0e70c4767454 |
|
MD5 | 8a267657a63f9f6060cd9c6b6a564ae3 |
|
BLAKE2b-256 | d50190fd8a8476cd3fb77d3a3aa73aa2681f94c3ad0b243016c5144f0036582f |
Hashes for django_admin_action_tools-0.1.0a1-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 3fa8f723e72b387580a11ac1cd1cb2cfba902a391d8c58ad5e2f173c93b567dd |
|
MD5 | 6c4ac26b1bdd0ad88a3a2d37056d5cdd |
|
BLAKE2b-256 | 771d202b6a0a6fb1924566ec4e766b574d1de58f7f0602134996f718e3543bb9 |