I have a ModelChoiceField
and a ChoiceField
that I need to pull out the "display name" for (not the "value").
For example, a ModelChoiceField
of a form renders the following output:
<select name="amodelfield" id="id_amodelfield">
<option value="">---------</option>
<option selected="selected" value="1">ABC</option>
<option value="2">DEF</option>
</select>
I want to be able to just render "ABC" since it is selected. If I do {{ field.value }}
as said in the docs, I get the value 1
instead of the ABC
I wanted. I also have a ChoiceField for which I want the same behavior.
Is there a easy way to do this without subclassing ModelChoiceField
, ChoiceField
and the Select
widget?
EDIT: Model.get_FOO_display()
would not work in this case