开发者

Django print choices value

开发者 https://www.devze.com 2023-01-26 16:33 出处:网络
EMP_CHOICES = ( (0,\'-- Select --\'), (1,\'Good\'), (2,\'Average\'), ) class EMPFeedback(models.Model): user_choices = models.IntegerField(choices=EMP_CHOICES)
EMP_CHOICES = (
         (0,'-- Select --'),
         (1,'Good'),
         (2,'Average'),
     )

class EMPFeedback(models.Model):
     user_choices = models.IntegerField(choices=EMP_CHOICES)

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 


There's a method for that! (™ Apple)

fb.get_user_choices_display()
0

精彩评论

暂无评论...
验证码 换一张
取 消