views:

222

answers:

1

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"
+4  A: 

get_FOO_display()

Daniel Roseman
+1 - but note that this is only useful if you need to get the value "Falafel" from a model instance.
Dominic Rodger