【发布时间】:2010-12-31 06:37:23
【问题描述】:
我根据模型创建了一个表单,如下所示:
class ContactSelectionForm(forms.ModelForm):
contacts = ManyToManyByLetter(Contact, field_name="first_name")
class Meta:
model = ContactSelection
exclude = ('created_by',)
当我处理这个视图时,我在 .html 输出中看到一个标有“联系人”的字段。 现在我想知道是否可以更改此输出。例如,我想将此字段命名为“选定联系人”而不是“联系人”。
这是.html模板的表单处理部分:
<form action="{{ request.path }}" method="POST">
<div>
<fieldset class="module aligned">
{% for field in form.visible_fields %}
<div class="form-row">
{# Include the hidden fields in the form #}
{% if forloop.first %}
{% for hidden in form.hidden_fields %}
{{ hidden }}
{% endfor %}
{% endif %}
{{ field.errors }}
{{ field.label_tag }} {{ field }}
</div>
{% endfor %}
<p><input type="submit" value="Save" /></p>
</fieldset>
</div>
</form>
如果有人想知道表单中的 ManyToManyByLetter(Contact, field_name="first_name") 是什么,请查看http://code.google.com/p/django-ajax-filtered-fields/。一个非常有用的 many2many javascript 库。
【问题讨论】:
标签: django django-templates django-forms