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.


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/


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.

链接地址: http://www.djcxy.com/p/11218.html

上一篇: 如何在android中获取wifi配置文件位置

下一篇: 将自定义操作添加到管理界面上的Django嵌入式对象