Django 打印选择值
EMP_CHOICES = (
(0,'-- Select --'),
(1,'Good'),
(2,'Average'),
)
class EMPFeedback(models.Model):
user_choices = models.IntegerField(choices=EMP_CHOICES)
如果user_choices在db中存储的值为1如何打印对应的user_choices对应的值(即1==GOOD)
fb = EMPFeedback.objects.get(id=1)
print fb.user_choices # prints 1
print fb.user_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
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
有一个 方法那! (™苹果)
There's a method for that! (™ Apple)