【发布时间】:2012-03-20 17:01:04
【问题描述】:
这是我的 forms.py 文件:
from django import forms
class MusicCheckboxForm(forms.Form):
songs = forms.MultipleChoiceField(widget=forms.CheckboxSelectMultiple())
我想使用 forms.py 文件生成带有复选框插入到第一列的多列表,但我不希望将 <input type="checkbox" ...> 硬编码到模板中。
我希望多列看起来像这样:
All song artist album genre date
[] aaa Smith fdaf rock 2001
[] bbb Davis fdsaf blue 2002
[] ccc Doe dfaj sjaf 2000
我的模板的 sn-p 如下所示:
<table class="list" summary="musics">
<caption>
music list
</caption>
<tr>
<th>All</th>
<th>song</th>
<th>artist</th>
<th>album</th>
<th>genre</th>
<th>date</th>
</tr>
{% for info in all_info %}
<tr>
<td>
<!-- I want put checkbox here -->
</td>
{% if info|hasattr:"title" %}
<td>{{ info.title }}</td>
{% else %}
<td></td>
{% endif %}
{% if info|hasattr:"artist" %}
<td>{{ info.artist }}</td>
{% else %}
<td></td>
{% endif %}
{% if info|hasattr:"album" %}
<td>{{ info.album }}</td>
{% else %}
<td></td>
{% endif %}
{% if info|hasattr:"genre" %}
<td>{{ info.genre }}</td>
{% else %}
<td></td>
{% endif %}
{% if info|hasattr:"date" %}
<td>{{ info.date }}</td>
{% else %}
<td></td>
{% endif %}
</tr>
{% endfor %}
</table>
【问题讨论】:
标签: python django forms checkbox