Where can a save confirmation page be hooked into the Django admin? (similar to delete confirmation)

I want to emulate the delete confirmation page behavior before saving certain models in the admin. In my case if I change one object, certain others should be deleted as they depend upon the object's now out-of-date state.

I understand where to implement the actual cascaded updates (inside the parent model's save method), but I don't see a quick way to ask the user for confirmation (and then rollback if they decide not to save). I suppose I could implement some weird confirmation logic directly inside the save method (sort of a two phase save) but that seems...ugly.

Any thoughts, even general pointers into the django codebase?


Asked by: Paul629 | Posted: 01-10-2021

Answer 1

You could overload the get_form method of your model admin and add an extra checkbox to the generated form that has to be ticket. Alternatively you can override change_view and intercept the request.

Answered by: Darcy894 | Posted: 02-11-2021

Answer 2

I'm by no means a Django expert, so this answer might misguide you.

Start looking somewhere around django.contrib.admin.options.ModelAdmin, especially render_change_form and response_change. I guess you would need to subclass ModelAdmin for your model and provide required behavior around those methods.

Answered by: Audrey700 | Posted: 02-11-2021

Answer 3

Have you considered overriding the administrative templates for the models in question? This link provides an excellent overview of the process. In this particular situation, having a finer-grained level of control may be the best way to achieve the desired result.

Answered by: Max643 | Posted: 02-11-2021

Similar questions

Still can't find your answer? Check out these communities...

PySlackers | Full Stack Python | NHS Python | Pythonist Cafe | Hacker Earth | Discord Python