Django templates: verbose version of a choice

前端 未结 8 1137
野性不改
野性不改 2020-11-30 18:16

I have a model:

from django.db import models

CHOICES = (
    (\'s\', \'Glorious spam\'),
    (\'e\', \'Fabulous eggs\'),
)

class MealOrder(models.Model):
          


        
8条回答
  •  [愿得一人]
    2020-11-30 18:37

    You have Model.get_FOO_display() where FOO is the name of the field that has choices.

    In your template do this :

    {{ scoop.get_flavor_display }}
    

提交回复
热议问题