How to get the label of a choice in a Django forms ChoiceField? How to get the label of a choice in a Django forms ChoiceField? django django

How to get the label of a choice in a Django forms ChoiceField?


See the docs on Model.get_FOO_display(). So, should be something like :

ContactForm.get_reason_display()

In a template, use like this:

{{ OBJNAME.get_FIELDNAME_display }}


This may help:

reason = form.cleaned_data['reason']reason = dict(form.fields['reason'].choices)[reason]


This the easiest way to do this: Model instance reference: Model.get_FOO_display()

You can use this function which will return the display name: ObjectName.get_FieldName_display()

Replace ObjectName with your class name and FieldName with the field of which you need to fetch the display name of.