Re: ChoiceField
On Jan 21, 2:14 pm, Shawn Milochik <sh...@milochik.com> wrote:
> What did you try?
>
> I found it easily.
>
> First:
> print dir(myform)
> #I found that myform has a 'fields' attribute.
>
> Second:
> print dir(myform.fields['choicefieldname'])
>
> #found myform.fields['choicefieldname'].choices
>
> Third:
> print myform.fields['choicefieldname'].choices
> #got all the nice options I was looking for!
>
> Then, in my template:
>
> {% for choice_value, choice_text in myform.fields.choicefieldname.choices %}
> choice_value: {{ choice_value }}<br/>
> choice_text: {{ choice_text }}<br/>
> {% endfor %}
>
> Shawn
I think there might be a terminology issue here. I suspect the OP is
looking for all the possible value of a model field with `choices`
set. Which, is not easily possible from a template (although you can
do it in Python: MyModel._meta.get_field_by_name('myfield')
[0].choices)
--
DR.

0 Comments:
Post a Comment
Subscribe to Post Comments [Atom]
<< Home