Thank you Chris Matthews for your reply. I'm working on a online examination system. I could able to generate some random questions from a data base containg hundreds of questions. So when ever a user answer and submit those random questions a dictionary contating a "Question_id and Answer" pair will be send as a request.
Now I have to get those dictionary keys first, i.e., the Question_id and then I have to cross check the values i.e., the values with the database values. On Feb 18, 4:37 pm, Chris Matthews <ch...@bbd.co.za> wrote: > 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: django-users@googlegroups.com [mailto:django-users@googlegroups.com] On > Behalf Of Chris Matthews > Sent: 18 February 2011 13:34 > To: django-users@googlegroups.com > 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: django-users@googlegroups.com [mailto:django-users@googlegroups.com] 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 django-users@googlegroups.com. > > To unsubscribe from this group, send email to > django-users+unsubscr...@googlegroups.com. > > For more options, visit this group > athttp://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 django-users@googlegroups.com. > To unsubscribe from this group, send email to > django-users+unsubscr...@googlegroups.com. > For more options, visit this group > athttp://groups.google.com/group/django-users?hl=en.- Hide quoted text - > > - Show quoted text - -- 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.