Home > Net >  How to get exact value of choice field in django
How to get exact value of choice field in django

Time:02-28

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

CodePudding user response:

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 }}

CodePudding user response:

{{your_variable_name.get_fieldname_display}} 
  • Related