gpt4 book ai didi

python - 从 Django 管理中删除历史按钮

转载 作者:太空狗 更新时间:2023-10-30 02:54:01 24 4
gpt4 key购买 nike

我想根据用户类型从 django 管理按钮启用/禁用历史记录。

enter image description here

我的最终目标是能够理解如何显示隐藏此按钮。

最佳答案

不幸的是,Django 没有提供一种简单的方法来切换历史记录按钮,例如为“添加”按钮所做的那样。最简单的方法是覆盖 change_form.html并从 block object-tools-items 中删除下一行:

<li>
{% url opts|admin_urlname:'history' original.pk|admin_urlquote as history_url %}
<a href="{% add_preserved_filters history_url %}" class="historylink">{% trans "History" %}</a>
</li>

请记住,您必须为每个管理模型指定 change_form。示例:

class TestAdmin(admin.ModelAdmin):
# path to the app_name/templates/admin/app_name/change_form.html
change_form_template = 'admin/app_name/change_form.html'

# Register your models here.
admin.site.register(Test, TestAdmin)

关于python - 从 Django 管理中删除历史按钮,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47495215/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com