django - Can not iterate a ChoiceField with Select as widget -
i have issues iterating on choicefield , building own html values , labels. when specifying "widget" parameter select, field not longer iterable.
however, works fine if specify radioselect.
the form:
class myformcreate( form ) : quotes = ( (34, "hi, patrick. wait, i'm patrick!"), (21, "i pie."), (76, "no, patrick!"), ) patrick = choicefield(choices = quotes, widget = select)
and template:
<select name="{{form.patrick.name}}"> {% option in form.patrick %} <option value="{{option.choice_value}}">{{option.choice_label}}</option> {% endfor %} </select>
what doing wrong?
(python 2.7.3 , django 1.4.5)
would you're looking for?
<select name="{{ form.patrick.name }}"> {% value, text in form.patrick.field.choices %} <option value="{{ value }}">{{ text }}</option> {% endfor %} </select>
also, white space friend. :)
Comments
Post a Comment