当前位置: 动力学知识库 > 问答 > 编程问答 >

django - Getting plain english from choice field in template

问题描述:

I have this in my model:

BEHV = (

('E', 'Externalizer'),

('I', 'Internalizer'),

)

# E or I ?

behavior_type = models.CharField(max_length=1, choices=BEHV)

And this in my template:

{{ s.behavior_type }}

Which renders

E

But I want it to render,

Externalizer

Instead. Is there I way to do this without swapping the tuples around in BEHV?

网友答案:

Just do this:

{{ s.get_behavior_type_display }}
分享给朋友:
您可能感兴趣的文章:
随机阅读: