On Sat, Oct 22, 2011 at 1:32 PM, Asif Jamadar <[email protected]> wrote:
> Can you explain this with example so that I can understand?

GENDERS = (
    ('U', 'Unspecified',),
    ('M', 'Male',),
    ('F', 'Female'),
 )

Now, say you have a
   gender = forms.ChoiceField( label='Gender', choices=GROUPS )
after validating a form containing this, you might get
   gender_in = form.cleaned_data['gender']
to be equal to 'M'. If I understood you correctly, you would want
to get 'Male' from this. As you know that the choices of the form
field came from choices, the straightforward way to do this
would be:
    for g in GENDERS:
        if g[0] == gender_in:
            gender_out = g[1]
gender_out now has what you need.

Regards,
Gora
_______________________________________________
BangPypers mailing list
[email protected]
http://mail.python.org/mailman/listinfo/bangpypers

Reply via email to