When using choices, I sometimes wanted to display the value of choices on the template side.
Therefore, I was able to display it by using get_xxx_display
, so I would like to make a note of it.
AREA_NAME_ASIA = 'asia'
AREA_NAME_EUROPE = 'europe'
AREA_NAME_CHOICES = (
(AREA_NAME_ASIA, 'Asia'),
(AREA_NAME_CHOICES, 'Europe'),
)
area = models.CharField(max_length=50, choices=AREA_NAME_CHOICES, verbose_name='Area name')
{{ obj.get_area_display }}
Now you can display Asia
.
You have to read the document properly, right?
Recommended Posts