I have a select field in the form and now I need to iterate over options in this field.
{{ form.myselect }}
gives me this:
<select name="myselect" id="id_myselect">
<option value="" selected="selected">---------</option>
<option value="2">Item 1</option>
<option value="3">Item 2</option>
...
</select>
Now I need to add some attributes to the options and because of that what I need is:
<select name="myselect" id="id_myselect">
{% for x in form.myselect %}
<option value="{{ x.id }}">{{ x.name }}</option>
{% endfor %}
</select>
but there is an error:
Caught TypeError while rendering: 'BoundField' object is not iterable
I tried form.myselect.all
, form.myselect.option_set
but it gives nothing
<option>
without the<select>
and no blank (-----
) option? or did I miss something? ... What are you trying to achieve specifically here? – Caritta