How to get exact value of choice field in django

Viewed 57

I have a choice field in Django model:

COMMITTEE_STATUS = (
    ("p", "Pending"),
    ("a", "Active"),
    ("c", "Completed"),
)

But the issue is when I am accessing these data in template I am getting p,a and c instead of actual pedning, active and complete

2 Answers

It's because first value is actually stored in database, the other is just for humans. You have to do additional thing to get second value. According to Django docs use this:

{{ yourobject.get_yourfield_display }}
{{your_variable_name.get_fieldname_display}} 
Related