一尘不染

Django打印选择值

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 

阅读 432

收藏
2020-04-02

共1个答案

一尘不染

fb.get_user_choices_display()
2020-04-02