我想在django的提交行中添加一個額外的按鈕。 標準我們得到「刪除」,「保存」,「保存並繼續編輯」和「保存並添加另一個」。爲了這個集合,我想添加另一個按鈕來調用模型上的一個函數。如何將按鈕添加到「submit_row」上下文中django
據我瞭解模板change_form
是在admin.views
其中之一產生的。上下文submit_row
作爲上下文傳遞。
我想編輯管理視圖的上下文。我在哪裏可以在我的文件系統中找到它?
我想在django的提交行中添加一個額外的按鈕。 標準我們得到「刪除」,「保存」,「保存並繼續編輯」和「保存並添加另一個」。爲了這個集合,我想添加另一個按鈕來調用模型上的一個函數。如何將按鈕添加到「submit_row」上下文中django
據我瞭解模板change_form
是在admin.views
其中之一產生的。上下文submit_row
作爲上下文傳遞。
我想編輯管理視圖的上下文。我在哪裏可以在我的文件系統中找到它?
從我可以告訴,有兩個相關的文件。首先是
.../django/contrib/admin/templatetags/admin_modify.py
它具有以下部分:
@register.inclusion_tag('admin/submit_line.html', takes_context=True)
def submit_row(context):
"""
Displays the row of buttons for delete and save.
"""
opts = context['opts']
change = context['change']
is_popup = context['is_popup']
save_as = context['save_as']
return {
'onclick_attrib': (opts.get_ordered_objects() and change
and 'onclick="submitOrderForm();"' or ''),
'show_delete_link': (not is_popup and context['has_delete_permission']
and (change or context['show_delete'])),
'show_save_as_new': not is_popup and change and save_as,
'show_save_and_add_another': context['has_add_permission'] and
not is_popup and (not save_as or context['add']),
'show_save_and_continue': not is_popup and context['has_change_permission'],
'is_popup': is_popup,
'show_save': True
}
而第二個是
.../django/contrib/admin/templates/admin/submit_line.html
是以下幾點:
{% load i18n %}
<div class="submit-row">
{% if show_save %}<input type="submit" value="{% trans 'Save' %}" class="default" name="_save" {{ onclick_attrib }}/>{% endif %}
{% if show_delete_link %}<p class="deletelink-box"><a href="delete/" class="deletelink">{% trans "Delete" %}</a></p>{% endif %}
{% if show_save_as_new %}<input type="submit" value="{% trans 'Save as new' %}" name="_saveasnew" {{ onclick_attrib }}/>{%endif%}
{% if show_save_and_add_another %}<input type="submit" value="{% trans 'Save and add another' %}" name="_addanother" {{ onclick_attrib }} />{% endif %}
{% if show_save_and_continue %}<input type="submit" value="{% trans 'Save and continue editing' %}" name="_continue" {{ onclick_attrib }}/>{% endif %}
</div>
你可能只是第二個添加一些自定義的html文件來顯示新的按鈕。
重寫塊標記submit_buttons_bottom在change_form.html
當你說「我在哪裏可以找到它在我的filesytem?」你的意思是更改表單管理模板? – nabucosound 2012-02-07 17:18:59
不,我是指以submit_row作爲其上下文呈現changeform.html的視圖 – jorrebor 2012-02-09 17:52:32
您是否解決了這個問題?如果是這樣,可否請您發佈您的解決方案。 – AgDude 2012-03-28 11:40:06