Oh and you probably wanted:

    if request.method=="POST":

        data = request.POST

       id_list = [int(x) for x in data.values()]



       questions = MyModel.objects.filter(id__in = id_list)


From: [email protected] [mailto:[email protected]] On 
Behalf Of Chris Matthews
Sent: 18 February 2011 13:34
To: [email protected]
Subject: RE: list indices must be integers not unicode


Hi Balu,



Numeric data from the form must be converted to int. I suspect you wanted to 
index data; not id_list.





    if request.method=="POST":

        data = request.POST

        temp_list = data.keys()

        id_list = []



       for i in temp_list:

             id_list.append(id_list[i])



       questions = MyModel.objects.filter(id__in = id_list)



Should

id_list.append(id_list[i])

Not be

id_list.append(data[i])





-----Original Message-----
From: [email protected] [mailto:[email protected]] On 
Behalf Of balu
Sent: 18 February 2011 13:24
To: Django users
Subject: list indices must be integers not unicode



Hi all :)



I'm processing a user submitted form. In that the user will answer a

series of multiple choice questions. Depending on the question "id"

which are submitted I'll find the compare the values and increment the

score to count his marks.



The question ids are  keys from the dictionary request.POST. But it is

showing an error the list indices must be integers not unicode. I

wrote the code as follows.





// In the view function



    if request.method=="POST":

        data = reques.POST

        temp_list = data.keys()

        id_list = []



       for i in temp_list:

             id_list.append(id_list[i])



       questions = MyModel.objects.filter(id__in = id_list)



--

You received this message because you are subscribed to the Google Groups 
"Django users" group.

To post to this group, send email to [email protected].

To unsubscribe from this group, send email to 
[email protected].

For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.


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

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

Reply via email to