Add custom action to Django inline object in admin interface

I have an admin interface that has a blog post, with built-in models that are versions of previous versions of the post.

I would like to add an action for each of the previous versions (A revert action, custom model method)

how should i do this? its similar to the ActionsActionAction keyword, but I want it to be inside the model view, not the list view, and also for each inline model, and not for the parent model

I would like to help.

to make it understandable

My previous_version class has a function called revert. all i want is that in my blog view in the admin panel, with every previous version I will have a link or button or something else. and clicking on it will call the previous_version.revert function.

+7
source share
2 answers

I think the right thing to do is admin actions as described in the documentation -

https://docs.djangoproject.com/en/dev/ref/contrib/admin/actions/

+2
source

You can extend Blog ModelAdmin with the revert action.

Overriding the built-in model template to add a button, as you said, is a good way to do this.

Just remember to create the created view in admin_view and allow only sending messages.

+1
source

All Articles