我对模型有疑问,例如我有
fallBack = models.CharField(max_length=100, choices=FALLBACK, default = 99,blank = True,null = True)
FALLBACK = (
(u'99','-'),
(u'standard', u'Standard TPF deactivation/exlusion applies'),
(u'fallback', u'Fallback script provided'),
(u'na',u'N/A'),
(u'other',u'Other'),
)
如果我将在模板中使用
{% for obj in form.forms %}
{{obj.fallBack}}
{% endfor %}
它会返回这样的东西
<select name="form-0-fallBack" id="id_form-0-fallBack">
<option value="">---------</option>
<option value="99" selected="selected">-</option>
<option value="standard">Standard TPF deactivation/exlusion applies</option>
<option value="fallback">Fallback script provided</option>
<option value="na">N/A</option>
<option value="other">Other</option>
</select>
但我想做这样的事情:
<select **onchange="javascript:make()"** name="form-0-fallBack" id="id_form-0-fallBack">
<option value="">---------</option>
<option value="99" selected="selected">-</option>
<option value="standard">Standard TPF deactivation/exlusion applies</option>
<option value="fallback">Fallback script provided</option>
<option value="na">N/A</option>
<option value="other">Other</option>
</select>
怎么做 ??我可以在模板中写这个第二个选项而不是 {{obj.fallBack}} 但是我的 formset.is_valid() 不起作用,什么时候我会做这样的事情:
1)I will choose from fallBack second option(Standard TPF deactivation/exlusion applies)
2) submit,
3) I have some error in other place in template
4) Then my obj.fallBack returning to default option (99 , -)
感谢帮助