Translated enum fields to template tags

I am trying to show an enumeration name in a template. To be clear, I have listed as a class inmodel.py

class EmployerWorkerNumberRange():
R_0 = 0
R_1_5 = 1
R_6_15 = 2
UNKNOWN = 3

EMPLOYER_WORKER_NUMBER_RANGE =(
    (R_0,_("wnr_0")),
    (R_1_5 ,_("wnr_1_5")),
    (R_6_15,_("wnr_6_15")),
    (UNKNOWN,_("UnknownWorkerNumberRange")),
)

When I use it in type form

wnr = forms.ChoiceField(label=_("emp_full_reg_wnr"), required=True, choices=EmployerWorkerNumberRange.EMPLOYER_WORKER_NUMBER_RANGE)

It works great. (Fills the dropdown menu with the translated values, and when I get the selected item, it turns only the identifier)

My question is how to show any translated value in my template by specifying its id. For example, I would like to use itEmployerWorkerNumberRange.EMPLOYER_WORKER_NUMBER_RANGE[0]

Could you suggest me?

thank

+5
source share
1 answer

, get_$var_display() ( choices) . :

{{ company.get_wnr_display }}

, , , , :

{{ some_value|as_wnr_title }}
+11

All Articles