Re: Getting the selected value on a Django forms.ChoiceField

1,960 views
Skip to first unread message

Tom Evans

unread,
Mar 28, 2013, 12:05:00 PM3/28/13
to django...@googlegroups.com
On Thu, Mar 28, 2013 at 3:10 PM, amine antri <amine...@gmail.com> wrote:
> i'm working on Djnago and i need to know how can i get selected value in
> forms.ChoiceField
>
> class FilterForm(forms.Form):
> Continent = forms.ChoiceField(choices=continents())
>
> i tried with :
>
> def affiche_all(request, currency):
> if request.method == 'POST':
> form = FilterForm(request.POST)
> if form.is_valid() :
> Continent = form.cleaned_data['Continent']

At this point, 'Continent' (variables should have lower case names,
see PEP 8) should have the chosen value from the choices.

> Continent = dict(form.fields['Continent'])[Continent]

I have no idea what this is attempting to do.


Cheers

Tom

Martin J. Laubach

unread,
Mar 28, 2013, 1:04:41 PM3/28/13
to django...@googlegroups.com

Continent = form.cleaned_data['Continent']

Continent = dict(form.fields['Continent'])[Continent]
  The obvious confusion stemming from the upper case variable aside, the second line is total nonsense. Drop it and you'll be golden.

  Cheers,

    mjl

Reply all
Reply to author
Forward
0 new messages