2010-11-25 67 views
36
EMP_CHOICES = (
     (0,'-- Select --'), 
     (1,'Good'), 
     (2,'Average'), 
    ) 

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

如果存儲在數據庫爲1 user_choices價值如何打印相應user_choices相應的值(即1個== GOOD)Django的打印選擇價值

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

回答

85

有應該是一個method! (™蘋果)

fb.get_user_choices_display() 
+1

============謝謝============ – Rajeev 2010-11-25 06:19:57