[Django]-Render label names instead of integer fields in Django templates

3👍

You need to use the following in your template:

{{ Model1.get_Choice_A_display }}

It will render the string instead of the integer

👤0sVoid

2👍

You do this with the .get_fieldname_display(…) method [Django-doc], so here get_Choice_A_display:

<th>Text</th><th>{{Model1.get_Choice_A_display }}</th>

Note: normally the name of the fields in a Django model are written in snake_case, not PascalCase, so it should be: choice_a instead of Choice_A.

Leave a comment