python - Django Querying a Choice Field -


on website display individual user created listings, when user creates listing of fields multiple choice , have stored these in list. here example of how typically have stored list

list -

area_code_choice = (     ('1', '021'),     ('2', '027'),     ('3', '022'),     ('4', 'other') ) 

the problem when try display choice query returns '1' rather '021', did try making both sides same ('021', '021') felt wasn't best way it.

html template -

({{ joblistings.area_code }})  

view -

job_listing = joblisting.objects.get(pk=pk) 

if please advise me on how other side of choice list great! cheers

you can use get_foo_display() in template

https://docs.djangoproject.com/en/1.9/ref/models/instances/#django.db.models.model.get_foo_display

{{ joblistings.get_area_code_display }}


Comments