Django打印选择值

EMP_CHOICES = (

(0,'-- Select --'),

(1,'Good'),

(2,'Average'),

)

class EMPFeedback(models.Model):

user_choices = models.IntegerField(choices=EMP_CHOICES)

如果存储在db中的user_choices值为1,如何打印对应的user_choices对应值(即1 == GOOD)

fb = EMPFeedback.objects.get(id=1)

print fb.user_choices # prints 1

print fb.user_choices.EMP_CHOICES

回答:

fb.get_user_choices_display()

以上是 Django打印选择值 的全部内容, 来源链接: utcz.com/qa/410337.html

回到顶部