forms.py
class TypeSelectionForm(forms.Form):
checkbox_field = forms.MultipleChoiceField(widget=forms.CheckboxSelectMultiple(), label="", required=False)
def __init__(self, type_id, *args, **kwargs):
super(TypeSelectionForm, self).__init__(*args, **kwargs)
_type_checkbox = self.fields['checkbox_field']
MY_CHOICES=((type.id, type.title) for type in type)
_type_checkbox.choices = MY_CHOICES
initial_val = []
type_selection = Types.objects.filter(parent_type_id=type_id,is_active=True)
for type_selection in type_selection:
initial_val.append(type_selection.id)
_type_checkbox.initial = initial_val
views.py
def types(method):
""""""""""""
types = TypeSelectionForm(type_id)
return render(request,'types.html',{'types':types})
In template I'm rendering the field like this,
types.html
{% for field in types.checkbox_field %}
<div class="deletelist">
{{field}}<br />
</div>
{% endfor %}
It is producing the html like this,
<ul>
<li><label for="id_checkbox_field_0"><input checked="checked" type="checkbox" name="checkbox_field" value="597" id="id_checkbox_field_0" /> comp lab</label></li>
<li><label for="id_checkbox_field_1"><input checked="checked" type="checkbox" name="checkbox_field" value="598" id="id_checkbox_field_1" /> phy lab</label></li>
<li><label for="id_checkbox_field_2"><input checked="checked" type="checkbox" name="checkbox_field" value="599" id="id_checkbox_field_2" /> chem lab</label></li>
</ul>
I want to replace the <ul>
and <li>
tag with <div class="class-name">
Need help.
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…