Omri
Omri

Reputation: 1087

Add custom action to Django inline object on the admin interface

I have an admin interface that has a blog post, with inline models which are previus versions of the post.

I'd like to add an action for each one of the previous version (A revert action, custom model method)

how should I go about doing that? its kinda similar to ModelAction actions keyword, but I want it to be inside the model view, not the list view and also its for each inline model, not for the parent model

would love some help.

to make it clearer

my previous_version class has a function named revert. all I want is that in my blog post's view in the admin panel by each previous version I'll have a link or button or something. and pressing it will call previous_version.revert.

Upvotes: 9

Views: 7451

Answers (2)

bmihelac
bmihelac

Reputation: 6323

You can extend Blog ModelAdmin with action revert.

Overriding inline model template to add a button, like you said you already did is a good way to do it.

Just be sure to wrap created view within admin_view and allow only post requests.

Upvotes: 1

Janis Lankovskis
Janis Lankovskis

Reputation: 1040

I guess the right thing to make this is Admin actions as described in documentation -

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

Upvotes: 2

Related Questions