In Django Combobox choices, how do you lookup description from short value?

Posted by MikeN on Stack Overflow See other posts from Stack Overflow or by MikeN
Published on 2010-03-26T14:29:41Z Indexed on 2010/03/26 14:33 UTC
Read the original article Hit count: 464

In Django models/forms the choices for a combobox often look like this:

food_choices = (("",""), ("1", "Falafel"), ("2", "Hummus"), ("3", "Eggplant Stuff, Babaganoush???"), 

So the value to be stored in the database will be 1/2/3, but the displayed value on the form will be the long description. When we are working in code outside a form, how can we quickly lookup the long description given the short value stored in the model?

So I want to map short values to long values:

>>print foo("1")
  "Falafel"

© Stack Overflow or respective owner

Related posts about django

Related posts about django-models