压倒一切的submit_line.html一个单一的模式或应用程序 [英] overriding submit_line.html for a single model or app
问题描述
我要重写submit_line.html为一个单一的模型或单一的应用程序(无论是将工作 - 应用程序只有一个模型)。我的文档看,我不能这样做(<一href="https://docs.djangoproject.com/en/1.5/ref/contrib/admin/#templates-which-may-be-overridden-per-app-or-model" rel="nofollow">https://docs.djangoproject.com/en/1.5/ref/contrib/admin/#templates-which-may-be-overridden-per-app-or-model)
I want to override submit_line.html for a single model or a single app (either will work - the app has just one model). I see in the docs I cannot do that (https://docs.djangoproject.com/en/1.5/ref/contrib/admin/#templates-which-may-be-overridden-per-app-or-model)
有没有一些方法来测试什么模式或应用程序正在呼吁这样我就可以加一些条件行为的模板?或者,也许是有一些办法已经制定submit_line.html的用于特定应用程序或模式不同的模板?
Is there some way to test for what model or app the template is being called for so I can add some conditional behaviour? Or perhaps is there some way to have a different template used in place of submit_line.html for a specific app or model?
mishbah的回答已经解决了我最初的问题,但现在我面临的另外一个问题 - 当我的code完成后,一些运行的添加行。我不希望这样的事情发生。
mishbah's answer has solved my initial problem, but now I am facing another issue - when my code is done, something runs that add the row. I don't want that to happen.
下面是什么,我试图完成的:
Here's what I am trying to accomplish:
- 在用户单击Add按钮
- 添加对象的页面显示我的自定义按钮
- 点击我的按钮,我执行一个Ajax调用,并显示以下附加格的结果,而这个页面显示,直到用户点击一个按钮。
这所有的作品 - 我唯一的问题是,一排被添加到数据库中 - 我会莫名其妙地喜欢prevent这种情况的发生。
This all works - my only issue is that a rows get added to the database - I would somehow like to prevent that from happening.
下面是我的code:
在主管理页面我刚才添加按钮:
On the main admin page I have just the add button:
下面是我的change_form.html:
Here is my change_form.html:
{% extends "admin/change_form.html" %}
{% block submit_buttons_bottom %}
<style type="text/css">
#id_tool_configuration {
white-space: pre-wrap;
}
</style>
<div class="submit-row">
<input value="Configure" class="default" name="configure" onclick="configureTools(document.getElementById('id_tool_configuration').value); " />
</div>
<script src="/static/scripts/jquery-1.7.js" type="text/javascript"></script>
<script type="text/javascript">
function configureTools(tcd) {
var toolConfigData = tcd;
var request = new XMLHttpRequest();
var params = 'toolConfigData='+encodeURIComponent(toolConfigData);
request.open('GET', '{% url 'motor.configuration.views.configure' %}?'+params);
request.setRequestHeader("Content-type", "text/plain; charset=utf-8");
request.onreadystatechange = function() {
if (request.readyState == 4) {
if (request.status == 200) {
status = 'Confguration results:';
}
else {
status = 'Confguration failed';
}
$('.submit-row').after(
$('<span />')
.html('<pre> ' + status + '\n' + request.responseText + '</pre>')
.after($('<button />').text('Return').click('function () { return; }'))
);
}
};
request.send(null);
return false;
};
</script>
{%端块%}
{% endblock %}
推荐答案
这是可以覆盖提交行
。简单地覆盖在你的ModelAdmin的 change_form
模板:
It is possible to override submit-row
. Simply override the change_form
template in your modeladmin:
class YourModelAdmin(admin.ModelAdmin):
change_form_template = 'path/to/custom/change_form.html'
和您的自定义 change_form.html
,你将需要:
And in your custom change_form.html
, you'll need to:
{% extends "admin/change_form.html" %}
和覆盖 submit_buttons_bottom
块:
{% block submit_buttons_bottom %}
{# custom submit row goes here #}
{% endblock %}
您可以定义自己的自定义 submit_row
templatetag,使用原来的templatetag为你的灵感:
You could define your own custom submit_row
templatetag, use the original templatetag for your inspiration:
请参阅<一href="https://github.com/django/django/blob/1101467ce0756272a54f4c7bc65c4c335a94111b/django/contrib/admin/templatetags/admin_modify.py#L24" rel="nofollow">https://github.com/django/django/blob/1101467ce0756272a54f4c7bc65c4c335a94111b/django/contrib/admin/templatetags/admin_modify.py#L24
这篇关于压倒一切的submit_line.html一个单一的模式或应用程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!