Django打印选择值 [英] Django print choices value
本文介绍了Django打印选择值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
EMP_CHOICES = (
(0,'-- Select --'),
(1,'Good'),
(2,'Average'),
)
class EMPFeedback(models.Model):
user_choices = models.IntegerField(choices=EMP_CHOICES)
如果存储在db中的值为1,为user_choices如何打印相应的user_choices相应的值(即1 == GOOD)
If the value stored in the db as 1 for user_choices how to print the corresponding user_choices corresponding value (i.e. 1==GOOD)
fb = EMPFeedback.objects.get(id=1)
print fb.user_choices # prints 1
print fb.user_choices.EMP_CHOICES
推荐答案
有一个方法为此! (™Apple)
There's a method for that! (™ Apple)
fb.get_user_choices_display()
这篇关于Django打印选择值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文