Django打印选择价值

时间:2010-11-25 06:15:52

标签: django django-models django-templates django-views

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)

fb = EMPFeedback.objects.get(id=1)
print fb.user_choices  # prints 1
print fb.user_choices.EMP_CHOICES 

1 个答案:

答案 0 :(得分:93)

有一个method! (™Apple)

fb.get_user_choices_display()