EMP_CHOICES = (
(0,'-- Select --'),
(1,'Good'),
(2,'Average'),
)
class EMPFeedback(models.Model):
user_choices = models.IntegerField(choices=EMP_CHOICES)
如果在数据库中用户选择的值为1,如何打印相应的用户选择值(即1==好)
fb = EMPFeedback.objects.get(id=1)
print fb.user_choices # prints 1
print fb.user_choices.EMP_CHOICES
{{ fb.get_user_choices_display }}
。 - Ajoy