可能重复:
Django打印选择值
在其中一个模型的Django中,我有以下枚举:
PRIORITY = (
('2', _(u'High')),
('1', _(u'Medium')),
('0', _(u'Low')),
)
priority = models.CharField(max_length=1, choices=PRIORITY, default='1')
Run Code Online (Sandbox Code Playgroud)
当向模板发送优先级时,该值仍然是整数,这不是很好.我想用文字而不是数字显示优先级.
context = Context({'priority':self.priority})
Run Code Online (Sandbox Code Playgroud)
有没有办法在将优先级发送到模板之前将优先级转换为实际字符串而不使用任何if语句?