下边是
表格.py:
GRADE_CHOICE=(
('1','Grade 1'),
('2','Grade 2'),
('3','Grade 3'),
('4','Grade 4'),
('5','Grade 5'),
('6','Grade 6') )
grades=forms.MultipleChoiceField(
choices=GRADE_CHOICE,
required=True,
widget=CheckboxSelectMultiple())
模板.html:
< divclass="controls">
{{ form.grades }}
< /div>
上面的代码工作正常,模板显示正确的数据。但是,它仅以一列或逐行显示数据。
<ul>
<li><label for="id_grades_0"><input type="checkbox" name="grades" value="1" id="id_grades_0" /> Grade 1</label></li>
<li><label for="id_grades_1"><input type="checkbox" name="grades" value="2" id="id_grades_1" /> Grade 2</label></li>
<li><label for="id_grades_2"><input type="checkbox" name="grades" value="3" id="id_grades_2" /> Grade 3</label></li>
<li><label for="id_grades_3"><input type="checkbox" name="grades" value="4" id="id_grades_3" /> Grade 4</label></li>
<li><label for="id_grades_4"><input type="checkbox" name="grades" value="5" id="id_grades_4" /> Grade 5</label></li>
<li><label for="id_grades_5"><input type="checkbox" name="grades" value="6" id="id_grades_5" /> Grade 6</label></li>
</ul>
有没有办法改变它,让它在一行中显示 3 条记录?