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.
In the case of a button, you'll want to use format_html . This will mark the relevant parts of the string safe, and so that it's displayed as an HTML button, and escape the other parts to protect against various securit issues. The values of object.id and object. some_property will get inserted into the placeholders.
Overview. The Django admin application can use your models to automatically build a site area that you can use to create, view, update, and delete records. This can save you a lot of time during development, making it very easy to test your models and get a feel for whether you have the right data.
One of the most powerful parts of Django is the automatic admin interface. It reads metadata from your models to provide a quick, model-centric interface where trusted users can manage content on your site. The admin's recommended use is limited to an organization's internal management tool.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With