gpt4 book ai didi

python - Django / python : How to cast an integer into the equivalent enum string?

转载 作者:行者123 更新时间:2023-11-28 16:46:01 25 4
gpt4 key购买 nike

<分区>

Possible Duplicate:
Django print choices value

在 Django 中的一个模型中,我有以下枚举:

PRIORITY = (
('2', _(u'High')),
('1', _(u'Medium')),
('0', _(u'Low')),
)

priority = models.CharField(max_length=1, choices=PRIORITY, default='1')

将优先级发送到模板时,该值仍然是整数,这不太好。我想用文字而不是数字来显示优先级。

context = Context({'priority':self.priority})

有没有办法在将优先级发送到模板之前不使用任何 if 语句将优先级转换为实际字符串?

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com