Это мой файл 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
Фрагмент моего шаблона выглядит так:
<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>