[英]Django admin add view popup dialog box
How can I pass in an extra GET
parameter in the add view popup box in the Django admin? 如何在Django管理员的添加视图弹出框中传递一个额外的GET
参数?
Basically I have a +
sign in a foreign key, and when I click on it, it opens a popup box to add a new object of that type. 基本上,我在外键中有一个+
号,当我单击它时,它会打开一个弹出框以添加该类型的新对象。
The problem is that I am using some custom Ajax code in the popup box, and I need to find a way to update only the field that is opened the dialog box (assuming there might be other foreign key fields). 问题是我在弹出框中使用了一些自定义Ajax代码,并且我需要找到一种方法来仅更新在对话框中打开的字段(假设可能还有其他外键字段)。
The only solution I can think of is to somehow pass in a GET
parameter so that I know which field should be updated. 我能想到的唯一解决方案是以某种方式传递GET
参数,以便我知道应更新哪个字段。
Any ideas? 有任何想法吗? I just need a push in the right direction in order to complete this 我只需要向正确的方向推动即可完成此操作
Right now I am doing something like this to update the field. 现在,我正在做类似的事情来更新这个领域。 and I want to make this dynamic 我想让它充满活力
if ($('#id_avatar').length) {
$('#id_avatar', opener.document).append($('<option selected="selected"></option>').attr('value', data.obj_id).text(data.obj__unicode__));
}
I guess I somehow reloading the select box in the original page could be an option since at this point its already saved in the database. 我想我可能会以某种方式在原始页面中重新加载选择框,因为此时它已保存在数据库中。
I ended up overriding the fieldsets in change_form.html
. 我最终覆盖了change_form.html
中的change_form.html
。 not sure if its the best approach but it seems to be working for me. 不知道这是否是最好的方法,但它似乎对我有用。 Now i can pass a source_field
to know what field called the popup so i can later updated the proper field with Jquery 现在我可以传递一个source_field
来知道哪个字段称为弹出窗口,以便以后可以使用Jquery更新适当的字段
{% for fieldset in adminform %}
{# {% include "admin/includes/fieldset.html" %}#}
<fieldset class="module aligned {{ fieldset.classes }}">
{% if fieldset.name %}<h2>{{ fieldset.name }}</h2>{% endif %}
{% if fieldset.description %}
<div class="description">{{ fieldset.description|safe }}</div>
{% endif %}
{% for line in fieldset %}
<div class="form-row{% if line.fields|length_is:'1' and line.errors %} errors{% endif %}{% if not line.has_visible_field %} hidden{% endif %}{% for field in line %}{% if field.field.name %} field-{{ field.field.name }}{% endif %}{% endfor %}">
{% if line.fields|length_is:'1' %}{{ line.errors }}{% endif %}
{% for field in line %}
<div{% if not line.fields|length_is:'1' %} class="field-box{% if field.field.name %} field-{{ field.field.name }}{% endif %}{% if not field.is_readonly and field.errors %} errors{% endif %}{% if field.field.is_hidden %} hidden{% endif %}"{% elif field.is_checkbox %} class="checkbox-row"{% endif %}>
{% if not line.fields|length_is:'1' and not field.is_readonly %}{{ field.errors }}{% endif %}
{% if field.is_checkbox %}
{{ field.field }}{{ field.label_tag }}
{% else %}
{{ field.label_tag }}
{% if field.is_readonly %}
<p>{{ field.contents }}</p>
{% else %}
{% if field.field.name == 'avatar' %}
<select id="id_avatar" name="avatar">
<option value="" selected="selected">---------</option>
</select><a href="/admin/core/multimedia/add/?_to_field=id&source_field=avatar" class="add-another" id="add_id_avatar" onclick="return showAddAnotherPopup(this);"> <img src="/static/admin/img/icon_addlink.gif" width="10" height="10" alt="Add Another"></a>
{% else %}
{{ field.field }}
{% endif %}
{% endif %}
{% endif %}
{% if field.field.help_text %}
<p class="help">{{ field.field.help_text|safe }}</p>
{% endif %}
</div>
{% endfor %}
</div>
{% endfor %}
</fieldset>
{% endfor %}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.