Package: django-admin-action-tools
Django Admin ConfirmFeaturesAdminConfirmMixin
Based ondjango-admin-confirmwith support fordjango-object-actionsAdminConfirmMixin 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.Ability to Confirm an action form with a preview of the objects and form dataAdd support to chain formScreenShotConfirm ScreenShotForm ScreenShotInstallationInstall django-admin-action-tools by running:poetry add django-admin-action-toolsAddadmin_action_toolstoINSTALLED_APPSin your project settings beforedjango.contrib.admin:INSTALLED_APPS = [
    ...
    'admin_action_tools',

    'django.contrib.admin',

    ...
    'widget_tweaks'
    ...
]To useActionFormMixinyou also need to addwidget_tweaksto theINSTALLED_APPSNote that this project follows the template override rules of Django.
To override a template, your app should be listed beforeadmin_confirm,admin_formin INSTALLED_APPS.Configuration OptionsEnvironment 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_TIMEOUTdefault: 1000ADMIN_CONFIRM_CACHE_KEY_PREFIXdefault: admin_confirm__file_cacheAttributes:confirm_changeOptional[bool]- decides if changes should trigger confirmationconfirm_addOptional[bool]- decides if additions should trigger confirmationconfirmation_fieldsOptional[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_templateOptional[string]- path to custom html template to use for change/addaction_confirmation_templateOptional[string]- path to custom html template to use for actionsNote that settingconfirmation_fieldswithout settingconfirm_changeorconfirm_addwould not trigger confirmation for change/add. Confirmations for actions does not use theconfirmation_fieldsoption.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) -> TemplateResponserender_action_confirmation(self, request: HttpRequest, context: dict) -> TemplateResponseUsageAdminConfirmMixinIt can be configured to add a confirmation page on ModelAdmin upon:saving changesadding new instancesperforming actionsConfirm Change:fromadmin_confirmimportAdminConfirmMixinclassMyModelAdmin(AdminConfirmMixin,ModelAdmin):confirm_change=Trueconfirmation_fields=['field1','field2']This would confirm changes on changes that include modifications onfield1and/orfield2.Confirm Add:fromadmin_confirmimportAdminConfirmMixinclassMyModelAdmin(AdminConfirmMixin,ModelAdmin):confirm_add=Trueconfirmation_fields=['field1','field2']This would confirm add on adds that setfield1and/orfield2to a non default value.Note:confirmation_fieldsapply to both add/change confirmations.Confirm Action:fromadmin_confirmimportAdminConfirmMixinclassMyModelAdmin(AdminConfirmMixin,ModelAdmin):actions=["action1","action2"]defaction1(modeladmin,request,queryset):# Do something with the queryset@confirm_action()defaction2(modeladmin,request,queryset):# Do something with the querysetaction2.allowed_permissions=('change',)This would confirmaction2but notaction1.Action confirmation will respectallowed_permissionsand thehas_xxx_permissionmethods.Note: AdminConfirmMixin does not confirm any changes on inlinesConfirm Object Action:fromadmin_confirmimportAdminConfirmMixinfromdjango_object_actionsimportDjangoObjectActionsclassMyModelAdmin(AdminConfirmMixin,DjangoObjectActions,ModelAdmin):change_actions=["action1"]@confirm_action()defaction1(self,request,object):# Do something with the objectAdminFormMixinAction Formfromadmin_confirmimportActionFormMixin,add_form_to_actionfrommyapp.formimportNoteActionFormfromdjango_object_actionsimportDjangoObjectActionsclassMyModelAdmin(ActionFormMixin,DjangoObjectActions,ModelAdmin):change_actions=["object_action"]@add_form_to_action(NoteActionForm)defaction1(modeladmin,request,queryset,form=None):# Do something with the queryset@add_form_to_action(NoteActionForm)defobject_action(modeladmin,request,object,form=None):# Do something with the objectChaining toolsfromadmin_confirmimportAdminConfirmMixin,ActionFormMixin,confirm_action,add_form_to_actionfromdjango_object_actionsimportDjangoObjectActionsfrommyapp.formimportNoteActionFormclassMyModelAdmin(AdminConfirmMixin,ActionFormMixin,DjangoObjectActions,ModelAdmin):change_actions=["action1"]@add_form_to_action(NoteActionForm)@confirm_action()defaction1(self,request,object,form=None):# Do something with the objectThis will chain form and confirmation.
The confirmation page will have the actions & form values displayed.
If you only want the action (same as confirm only), you can pass the following argumentfromadmin_confirmimportAdminConfirmMixin,ActionFormMixin,confirm_action,add_form_to_actionfromdjango_object_actionsimportDjangoObjectActionsfrommyapp.formimportNoteActionFormclassMyModelAdmin(AdminConfirmMixin,ActionFormMixin,DjangoObjectActions,ModelAdmin):change_actions=["action1"]@add_form_to_action(NoteActionForm)@confirm_action(display_form=False)defaction1(self,request,object,form=None):# Do something with the object and formfromadmin_confirmimportAdminConfirmMixin,ActionFormMixin,confirm_action,add_form_to_actionfromdjango_object_actionsimportDjangoObjectActionsfrommyapp.formimportNoteActionForm,SecondFormclassMyModelAdmin(AdminConfirmMixin,ActionFormMixin,DjangoObjectActions,ModelAdmin):change_actions=["action1"]@add_form_to_action(NoteActionForm)@add_form_to_action(SecondForm)@confirm_action()defaction1(self,request,object,forms=None):# Do something with the object and formsThis will chain 2 forms and confirmation.
The confirmation page will have the actions & form values displayed.if you want to not display the impacted objects, you can usefromadmin_confirmimportAdminConfirmMixin,ActionFormMixin,confirm_action,add_form_to_actionfromdjango_object_actionsimportDjangoObjectActionsfrommyapp.formimportNoteActionForm,SecondFormclassMyModelAdmin(AdminConfirmMixin,ActionFormMixin,DjangoObjectActions,ModelAdmin):change_actions=["action1"]@add_form_to_action(NoteActionForm,display_queryset=False)@add_form_to_action(SecondForm,display_queryset=False)@confirm_action(display_queryset=False)defaction1(self,request,object,forms=None):# Do something with the object and formsDevelopmentCheck out ourdevelopment processif you're interested.