你好,我有一个模板表单,显示项目列表。这个模板被称为edit_order.html。我希望能够从另一个项目列表中添加一个新项目。从另一个项目列表是一个名为items.html的模板,显示项目列表。在items.html中,每个项目除了项目之外还有一个复选框。现在,我想要做的仅仅是当项目已经在edit_order模板中列出的时候,使复选框被标记。现在,所有的项目都被标记。但我不想要这个。Django复选框问题
edit_order.html
{% for item in items %}
<tr>
<td><input type="checkbox" name="item" value="{{item.pk}}" checked="checked"></td>
<td>{{item.tiptop_id}}</td><td>{{item.alternative_id}}</td><td>{{item.title}}</td>
<td>{{item.type}}</td><td>{{item.format}}</td>
</tr>
{% endfor %}
item.html
{% extends "base_menu.html" %}
{%block script%}
<script type="text/javascript">
$(function(){
$("#check_all").click(function(){
if(this.checked ==true)
$("tbody :checkbox").each(function(){
this.checked=true;
});
else
$("tbody :checkbox").each(function(){
this.checked=false;
});
});
});
</script>
{%endblock%}
<td><a href="{% url tiptop.views.edit_item item.client.pk item.pk %}" onclick="return showAddAnotherPopup(this);">Edit</a></td>
</tr>
{% endfor %}
</tbody>
</table></fieldset>
</div>
<div id="form_footer">
<input type="submit" value="Request Delivery" onclick="change_action('{% url tiptop.views.service_order client.pk 1 %}')">
<input type="submit" value="Request Pick Up" onclick="change_action('{% url tiptop.views.service_order client.pk 2 %}');validate_status(this.form)">
</div>
</form>
{% endblock %}
{% block right_content %}
<div id="location_header">{{client}}: Search results</div>
<form action="{% url tiptop.views.service_order client.pk 1 %}" method="post" onsubmit="return validate_selection(this)">
<div class="form_container">
<fieldset class="model">
<table id="items_table">
<thead>
<tr>
<th><input type="checkbox" id="check_all" checked="checked"></th>
<th scope="col">Tiptop no.</th><th scope="col">Client no.</th><th scope="col">Title</th><th scope="col">Type</th>
<th scope="col">Format</th><th scope="col">Status</th><th scope="col">Date</th>
</tr>
</thead>
<tbody>
{% for item in items %}
<tr class="items_table_row">
<td><input type="checkbox" name="{{item.pk}}" value="{{item.pk}}" checked="checked"></td>
<td>{{item.tiptop_id}}</td><td>{{item.alternative_id}}</td><td>{{item.title}}</td><td>{{item.type}}</td><td>{{item.format}}</td>
<td><span id="{{item.pk}}" name="type">{{item.itemstatushistory_set.latest}}</span></td><td>{{item.itemstatushistory_set.latest.date.date|date:"d M Y"}}</td>
我正在使用django表单。我没有上传我的意见。我也有一个清单。我有一个列出项目的模板。从这个模板我想能够添加一个项目。现在当我的意思是通过添加一个项目,我不是通过创建一个表单。我的意思是,去页面列出所有现有的客户端项目(我有这个模板)。在此模板中有一个列表,您可以选择要添加的现有项目。我遇到问题的是复选框。出于某种原因,我的代码中都是“勾选”的。我希望勾选模板项目列表中的项目,并留空。 – Shehzad009 2011-01-31 15:31:15