动态修改模板中的Django表单

时间:2015-08-26 16:46:08

标签: html django django-forms django-templates

我在名为channels.html的页面中显示了来自我的数据库的100个对象

在一个名为“is_new”的复选框字段中,我可以从DB中检索该特定行的数据,

channels.html

nearestLocationApp.controller("getTheLocation", function($scope, allTheLocationsFactory){

    allTheLocationsFactory.then(function(data){
        $scope.locations = data;
        console.log($scope.locations);
    })

});

手动根据DB中的值更改复选框值。通过自己编写HTML代码。它虽然工作,但是     但我想通过访问form.values,form.id,form.name和其他html元素在模板中动态完成。

{% for each_channel in channels_list %}
    .....
     ....... other elements.....

<td id="is_new">
**Attention here:{{form.is_new.value}} //--> I need to modify this **

简而言之,我不想在我的表格中使用任何“默认”或“初始”。我想要动态价值..

// 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 >

我可以在模板中进行吗?谢谢。

使用Django 1.5。

0 个答案:

没有答案
相关问题