Html 动态修改模板中的Django表单
我正在一个名为channels.html的页面中显示数据库中的100个对象 在一个名为“is_new”的复选框字段中,我能够从数据库中检索特定行的数据 channels.htmlHtml 动态修改模板中的Django表单,html,django,django-forms,django-templates,Html,Django,Django Forms,Django Templates,我正在一个名为channels.html的页面中显示数据库中的100个对象 在一个名为“is_new”的复选框字段中,我能够从数据库中检索特定行的数据 channels.html {% for each_channel in channels_list %} ..... ....... other elements..... <td id="is_new"> **Attention here:{{form.is_new.value}} //--> I nee
{% for each_channel in channels_list %}
.....
....... other elements.....
<td id="is_new">
**Attention here:{{form.is_new.value}} //--> I need to modify this **
我可以用模板做吗?谢谢
我正在使用Django 1.5。@GwynBleidD您能看看这个吗。@duffn,请检查一下,有人能回答这个问题吗?
// If the DB value is 1 then set the "yes" as checked and "No" as unchecked.
// Set "Yes" as checked.
{% if each_channel.is_new%}
<span class="text-success" for="id_is_new_0">
<input id="id_is_new1_{{each_channel.usid}}" class="id_is_new" name="is_new{{each_channel.usid}}" type="radio" value="1"checked="true"> Yes</span>
**// set "NO" unchecked**
<span for="id_is_new_1">
<input id="id_is_new0_{{each_channel.usid}}" class="id_is_new" name="is_new{{each_channel.usid}}" type="radio" value="0"> No</span>
*// Vice versa - If the DB value is 0, then do the vice versa.*
{%else%}
**// Set "Yes" Unchecked.**
<span for="id_is_new_0">
<input id="id_is_new1_{{each_channel.usid}}" class="id_is_new" name="is_new{{each_channel.usid}}" type="radio" value="1"> Yes</span>
**// Set "NO" Checked**
<span class="text-danger" for="id_is_new_1">
<input id="id_is_new0_{{each_channel.usid}}" class="id_is_new" name="is_new{{each_channel.usid}}"type="radio" value="0" checked="True"> No</span>
{%endif%}
</td >
IF MY DB Value is THIS :
Change my Form value, ID, Name to XXX
ELSE:
Change my Form value, ID, Name to YYY.