Django print choices value

DjangoDjango ModelsDjango TemplatesDjango Views

Django Problem Overview


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 

Django Solutions


Solution 1 - Django

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionRajeevView Question on Stackoverflow
Solution 1 - DjangoIgnacio Vazquez-AbramsView Answer on Stackoverflow