Django POST Arrays

31 views
Skip to first unread message

G Z

unread,
Aug 7, 2014, 6:27:45 PM8/7/14
to django...@googlegroups.com
I'm doing some query and database stuff outside of what django is capable of and I need some help with how I get all the values of a POSTED Dictionary list.

here is the POST values because im using a multiple select box that are send to django 
u'licenses': [u'26.0', u'16.0', u'13.0', u'166.0'],

I need to insert these licenses for the vm that was selected. Thus, I need to be able to get at each one and save into a list. 
However all I can seem to get to is the very last one. This has something to do with the way django is parsing the information.

So here is my code:
I've tried teh following:

selected_lic.append(selected_customer['licenses'])
 
This will output the following 
[u'166.0']

for license in selected_customer['licenses']:
      selected_lic.append(license)
This will out put the following
[u'1','6','6','.','0']

Why can't i get to the rest of the data? Why does it only take the last value. Even if I just set a var to the selected post value it will only take the last one.

[u'166.0']

Tom Evans

unread,
Aug 7, 2014, 6:38:28 PM8/7/14
to django...@googlegroups.com
QueryDict objects do not work like that, if you simply index the
QueryDict by keyname, and the key refers to a list of values, then the
last value in the list is returned. It is a string, and you are then
iterating through that character by character.

https://docs.djangoproject.com/en/1.6/ref/request-response/#django.http.QueryDict.__getitem__

Use QueryDict.getlist() instead:

https://docs.djangoproject.com/en/1.6/ref/request-response/#django.http.QueryDict.getlist

Cheers

Tom

G Z

unread,
Aug 11, 2014, 12:47:36 PM8/11/14
to django...@googlegroups.com
Thanks so much
Reply all
Reply to author
Forward
0 new messages