[BangPypers] Getting label of the choicefield in django form

Gora Mohanty gora at mimirtech.com
Sat Oct 22 09:20:25 CEST 2011


On Sat, Oct 22, 2011 at 12:45 PM, Asif Jamadar <asif.jamadar at rezayat.net> wrote:
> But I have same lables( or names) in my choice list
>
> Choices = [ ('attr1', 1), ('attr1', 2), ('attr1' , 3) , ('attr2', 1), ('attr2', 2), ('attr2', 3) ]
>
> All these are displayed as radio buttons.
>
> When I select 2 then it is returning me "attr1". But how should I get the value itself that is "2"?

Umm, this is not the label. Please be clear about what you want.

I don't think that you can get that from form.cleaned_data, but
again, given the value from form.cleaned_data, and given that
you already know the choices themselves, can't you simply look
these up.

Regards,
Gora


More information about the BangPypers mailing list