python - django :: How to style a CheckboxSelectMultiple in a form? -
forms.py
class formentry(forms.modelform): class meta: model = entry fields = ['name','price','share'] widgets = { 'share':forms.checkboxselectmultiple(), }
after passing template:
<ul id="id_share"> <li><label for="id_share_0"><input id="id_share_0" name="share" type="checkbox" value="2"> lily</label></li> <li><label for="id_share_1"><input id="id_share_1" name="share" type="checkbox" value="1"> rabbit</label></li> </ul>
now want rid of ul , li, also, use bootstrap3's button group style it, this
<div class="btn-group" data-toggle="buttons"> <label class="btn btn-primary"> <input id="id_share_0" name="share" type="checkbox" value="2"> lily </label> <label class="btn btn-primary"> <input id="id_share_1" name="share" type="checkbox" value="1"> rabbit </label> </div>
it ideal if can give me general solution, instead of passing specific values views.py, idea write widget, can't figure out how.
i know i'm noob, please help.
as of django 1.6, you can loop:
<div class="btn-group" data-toggle="buttons"> {% checkbox in myform.shares %} <label class="btn btn-primary"> {{ checkbox.tag }} {{ checkbox.choice_label }} </label> {% endfor %} </div>
Comments
Post a Comment