0
<form method="post" action=".">
{% csrf_token %}
<table width="100%" cellpadding="0" cellspacing="0" >
<tr>
<td colspan="2" class="incident-type">
{% for type in typeList%}
{% if type.parent_type_id == None %}
<h1>{{type.title}}</h1>
{% else %}
{% if checked_ones %}
<label><input type="checkbox" checked="True" value="{{ type.title }}" name="key">{{ type.title }}</label><br />
{% else %}
<label><input type="checkbox" value="{{ type.title }}" name="key">{{ type.title }}</label><br />
{% endif %}
{% endfor %}
看到這裏,複選框,輸入從該行獲得的views.py
checked_ones = [unicode(x) for x in subtype if unicode(x) in request.POST.getlist('key')]
這裏的問題是,如果選項中的任何一個被檢查並保存,所有其他複選框選項都被選中(在頁面重定向之後)。
嘗試了一些邏輯循環,需要一些幫助。
是的,它工作正常...感謝僧侶 – user2086641