<https://lh4.googleusercontent.com/-AoDaDPxkJuM/UiXeqgoQRBI/AAAAAAAAAAM/X6QgTCNluqM/s1600/Screenshot-2.png>
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%}
{{field}}<br />
{% endfor %}
It is producing the html like this,
<ul>
<li><label for="id_checkbox_field_12"><input checked="checked"
type="checkbox" name="checkbox_field" value="674" id="id_checkbox_field_12"
/> field1</label></li>
<li><label for="id_checkbox_field_13"><input checked="checked"
type="checkbox" name="checkbox_field" value="675" id="id_checkbox_field_13"
/> field2</label></li>
<li><label for="id_checkbox_field_14"><input checked="checked"
type="checkbox" name="checkbox_field" value="676" id="id_checkbox_field_14"
/> field3</label></li>
<li><label for="id_checkbox_field_15"><input checked="checked"
type="checkbox" name="checkbox_field" value="677" id="id_checkbox_field_15"
/> field4</label></li>
</ul><br />
I want to add a small round image(css class) to all choices. I tried the
below, but it is rendering the image only one time. Example if 4 items are
rendered with checkbox, only one image is getting rendered. Please see the
sample image below.
This is the tried one but not working
{% for field in types%}
<input style="margin: 8px -3px;float: left;" type="button"
class="delete_types" id="delete_name"/>
{{field}}<br />
{% endfor %}
![sample image][1]
I want to add that red round image to all check box item. How to do it in
Django?
--
You received this message because you are subscribed to the Google Groups
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/django-users.
For more options, visit https://groups.google.com/groups/opt_out.