首页 > 解决方案 > Customize form actions in django admin

问题描述

I have followed this article on "How to Add Custom Action Buttons to Django Admin" https://medium.com/@hakibenita/how-to-add-custom-action-buttons-to-django-admin-8d266f5b0d41 and I have it almost working. I would like display fields that are pre-populated with values from my model.

Here is what I have so far.

enter image description here

From this page the user can click on the 'Approve' or 'Deny' buttons. The deny form is simple and looks like this:

enter image description here

Here the user needs to type in a reason for denying and then can click the Submit button to execute custom code to process the denial.

If the user clicks Approve I would like the user to have the ability to adjust some of the values in my Command model so I need to display those values in the form. So the form would look much like the standard django admin Change form but with just a Submit button that when clicked would update the model with user's changes and call my custom code to process the approval. So the Approval form would look something like this:

enter image description here

But I cannot figure out how to get the values for nonroot_risk and nopasswd_risk from my model to display in the form.

标签: djangodjango-admin

解决方案


推荐阅读