Skip to main content

Adds confirmation to Django Admin changes, additions and actions

Project description

Django Admin Confirm

PyPI Tests Status Coverage Status PyPI - Python Version PyPI - Django Version PyPI - License

AdminConfirmMixin is a mixin for ModelAdmin to add confirmations to change, add and actions.

Screenshot of Change Confirmation Page

Screenshot of Add Confirmation Page

Screenshot of Action Confirmation Page

It can be configured to add a confirmation page on ModelAdmin upon:

  • saving changes
  • adding new instances
  • performing actions

Typical Usage:

    from admin_confirm import AdminConfirmMixin

    class MyModelAdmin(AdminConfirmMixin, ModelAdmin):
        confirm_change = True
        confirmation_fields = ['field1', 'field2']

Disclaimer

Be aware that not all possible combinations of ModelAdmin have been tested, even if test coverage is high.

See testing readme for more details

Installation

Install django-admin-confirm by running:

pip install django-admin-confirm

Python Support

  • Supported: Python 3.10 - 3.14

Add to INSTALLED_APPS in your project settings before django.contrib.admin:

INSTALLED_APPS = [
    ...
    'admin_confirm',

    '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 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: 1000
  • ADMIN_CONFIRM_CACHE_KEY_PREFIX default: admin_confirm__file_cache

Attributes:

  • confirm_change Optional[bool] - decides if changes should trigger confirmation
  • confirm_add Optional[bool] - decides if additions should trigger confirmation
  • confirmation_fields Optional[Array[string]] - sets which fields should trigger confirmation for add/change. If not set or set to __all__, it will trigger for all fields. For adding new instances, the field would only trigger a confirmation if the field is set to a value that's not its default.
  • change_confirmation_template Optional[string] - path to custom html template to use for change/add
  • action_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

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, confirm_action

    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

Contribution & Appreciation

Contributions are most welcome :) Feel free to:

  • address an issue
  • raise an issue
  • add more test cases
  • add feature requests

Your appreciation is also very welcome :) Feel free to:

  • star the project
  • open an issue just to share your thanks

Check out our development process if you're interested.

Support

If you are having issues, please let us know through raising an issue.

License

The project is licensed under the Apache 2.0 license.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

django_admin_confirm-1.3.0.tar.gz (16.3 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

django_admin_confirm-1.3.0-py3-none-any.whl (16.9 kB view details)

Uploaded Python 3

File details

Details for the file django_admin_confirm-1.3.0.tar.gz.

File metadata

  • Download URL: django_admin_confirm-1.3.0.tar.gz
  • Upload date:
  • Size: 16.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for django_admin_confirm-1.3.0.tar.gz
Algorithm Hash digest
SHA256 0ca002fa67dc03435b83fd0478f4ab4cb3319369f6dcf7cfe6d30065e01a4c19
MD5 0cd6d2f0af49b555bf6c731387f9b872
BLAKE2b-256 c44fd831bef167c589245287ec1c2fc8714e3e41add2784488d89a5a47ba2890

See more details on using hashes here.

Provenance

The following attestation bundles were made for django_admin_confirm-1.3.0.tar.gz:

Publisher: release.yml on TrangPham/django-admin-confirm

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file django_admin_confirm-1.3.0-py3-none-any.whl.

File metadata

File hashes

Hashes for django_admin_confirm-1.3.0-py3-none-any.whl
Algorithm Hash digest
SHA256 f9870eef2ba89dcc43886373e56c3b25047579cef0f44719dc83896311022b5d
MD5 e902ec42073f9de51253eac0417e4713
BLAKE2b-256 c93c1bdb5030221c351aee81db9aff1530f9350cca3f1deb450a035c657185f6

See more details on using hashes here.

Provenance

The following attestation bundles were made for django_admin_confirm-1.3.0-py3-none-any.whl:

Publisher: release.yml on TrangPham/django-admin-confirm

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page