This is my forms.py file:
from django import forms
class MusicCheckboxForm(forms.Form):
songs = forms.MultipleChoiceField(widget=forms.CheckboxSelectMultiple())
I want use the forms.py file to produce the multi-columns table with the checkbox insert to the first column, But I don’t want hard code <input type="checkbox" ...> to the template.
And I want the multi-columns look like this:
All song artist album genre date
[] aaa Smith fdaf rock 2001
[] bbb Davis fdsaf blue 2002
[] ccc Doe dfaj sjaf 2000
The snippet of my template looks like this:
<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>
django-tables2simplifies transforming data into HTML tables. It does for HTML tables whatdjango.formsdoes for HTML forms..See this : http://django-tables2.readthedocs.org/en/latest/index.html