Hi there,
i was writing some unit-tests for a django-admin based software interacting with the changelist view. The test involves selecting a few rows and calling an action, so there is code like:
from django.http import QueryDict
params = QueryDict(mutable=True)
...
for pk in pks_to_select:
params.appendlist("_selected_action", pk)
client.post(url, params)
I found it convenient to use the QueryDict to construct the form parameters for post. However, it took me an hour to debug why only the last “_selected_action” is posted in the multipart form data.
When i found out, it perfectly makes sense: The QueryDict._getitem_ only returns the last item of a list value, while a normal dict._getitem_ returns the whole list.
I just wonder if it makes sense to add this tip to the Client.post documentation:
Something like:
If you are using a QueryDict or MultiValueDict to construct the post parameters, be sure to cast it to dict before passing it to post:
client.post(url, dict(my_query_dict))
Thank you!