答案 0 :(得分:4)
不幸的是,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)
答案 1 :(得分:0)
一个干净的解决方案是覆盖change_form_object_tools.html
template,该templates/admin/
必须放置在项目的 {% load i18n admin_urls %}
{% block object-tools-items %}
{% block comment %}
<li>
{% url opts|admin_urlname:'history' original.pk|admin_urlquote as history_url %}
<a href="{% add_preserved_filters history_url %}" class="historylink">
{% translate "History" %}</a>
</li>
{% endcomment %}
{% if has_absolute_url %}<li><a href="{{ absolute_url }}" class="viewsitelink">{% translate "View on site" %}</a></li>{% endif %}
{% endblock %}
中。
function beforeLoad(scriptContext) {
var rec = scriptContext.newRecord;
var sublistObj = rec.getSublist({
sublistId: 'item'
});
var columnObj = sublistObj.getColumn({
fieldId: 'rate'
});
columnObj.isMandatory = true;
log.debug({
title: 'rate is mandatory',
details: columnObj.isMandatory
});
}