On Mon, Mar 2, 2009 at 12:42 PM, <natx...@gmail.com> wrote:

>
> I've got an error using ModelMultipleChoiceField, but don't guess
> where:
>
> my form is :
>
> class SearchForm(forms.Form):
>    titulos = forms.ModelMultipleChoiceField(Titulo.objects.all
> ().order_by('tipo'), label='Títulos')
>
> in my template I insert it with:
>
> <form  method="POST" action="/curriculums/buscarCurriculum">
> {% for field in form %}
>    <span>{{ field.label_tag }}</span>
>    <span>{{ field }}</span>
> {% endfor %}
> <span><input type="image" src="/media/img/admin/icon_addlink.gif"
> alt="Submit button"></span>
> </form>
>
> but when I try to get values in my view:
>
> if request.POST:
>    num=len(request.POST['titulos'])
>    titulos=[ Titulo.objects.filter(pk=i) for i in request.POST
> ['titulos']
>    post=request.POST
>
> I get the next values:
> titulos: [<Titulo: Licenciatura, Biología>] (note that's only one)
> num: 1
> POST: <QueryDict: {u'y': [u'2'], u'titulos': [u'1', u'2'], u'x':
> [u'9']}>
>
> It seems that POST is ok, but cannot process it
>
> ¿any help?
> >
>
by default subscriping on a QueryDict object gives only the first item, so
you want request.POST.getlist('titulos').

Alex

-- 
"I disapprove of what you say, but I will defend to the death your right to
say it." --Voltaire
"The people's good is the highest law."--Cicero

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to