Is there a way to get custom Django admin actions to appear on the “change” view in addition to the “change list” view?

后端 未结 3 702
一整个雨季
一整个雨季 2021-02-01 02:58

I thought for whatever reason this would be easy to do, but I looked deeper and it appears there is no straightforward way to allow users to execute custom admin actions on the

3条回答
  •  予麋鹿
    予麋鹿 (楼主)
    2021-02-01 03:23

    What I did was create my own MYAPP/templates/admin/MYMODEL/change_form.html template:

    {% extends "admin/change_form.html" %}
    {% load i18n %}
    {% block object-tools %}
    {% if change %}{% if not is_popup %}
    
    {% endif %}{% endif %}
    {% endblock %}
    

    So I basically only changed the block "object-tools" where the history-link and the "view on site"-link are. the rest of the original change_form.html remains untouched. BTW: "original.id" is the id of the model you are editing.

提交回复
热议问题