Django: Display Choice Value

后端 未结 3 955
心在旅途
心在旅途 2020-12-02 04:03

models.py:

class Person(models.Model):
    name = models.CharField(max_length=200)
    CATEGORY_CHOICES = (
        (\'M\', \'Male\'),
              


        
3条回答
  •  醉话见心
    2020-12-02 04:51

    It looks like you were on the right track - get_FOO_display() is most certainly what you want:

    In templates, you don't include () in the name of a method. Do the following:

    {{ person.get_gender_display }}
    

提交回复
热议问题