class AddRoleForm(forms.Form):
roles=forms.ModelMultipleChoiceField(queryset=Role.objects.all(),widget=forms.CheckboxSelectMultiple())
在模板中:</p>
{{ form.roles }}
结果是这样的:
<ul>
<li><label for="id_roles_0"><input type="checkbox" value="1" name="roles" id="id_roles_0"> User object</label></li>
<li><label for="id_roles_1"><input type="checkbox" value="2" name="roles" id="id_roles_1"> User object</label></li>
</ul>
我想在每一行中显示角色的名称,并在 chebox 中获取角色的 id,例如:
<ul>
<li><label for="id_roles_0"><input type="checkbox" value="100" name="roles" id="id_roles_0">boss</label></li>
<li><label for="id_roles_1"><input type="checkbox" value="101" name="roles" id="id_roles_1">employee</label></li>
</ul>
我应该怎么办?