Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

provides support for query array notation #548

Conversation

pySilver
Copy link

@pySilver pySilver commented Nov 5, 2016

Adds support for array inputs using QueryArrayWidget:

1. Values can be provided as csv string: ?foo=bar,baz
2. Values can be provided as query array: ?foo[]=bar&foo[]=baz

See: #544

QueryArrayWidget might be set as a default widget for DRF MultipleChoiceFilters since this feature is mostly useful there.

Why we need this feature: Many frontend libraries uses common format to pass array-like structures in URLs:

http://api.jquery.com/jquery.param/
https://coderwall.com/p/uh8kiw/pass-arrays-objects-via-querystring-the-rack-rails-way

This feature is mostly useful in DRF/API projects where Django is not responsible for frontend code and has no influence on it. It just supports seems-to-be popular input format for arrays.

@rpkilby
Copy link
Collaborator

rpkilby commented Nov 5, 2016

QueryArrayWidget might be set as a default widget for DRF MultipleChoiceFilters since this feature is mostly useful there.

Don't forget the browsable API. The <select multiple> widget still submits foo=bar&foo=baz, where as this accepts foo[]=bar&foo[]=baz). Would it be possible to support all three syntaxes?

@pySilver
Copy link
Author

pySilver commented Nov 5, 2016

@rpkilby yes it works out of the box. I've made some adjustments to protect data coming as ?foo=1,2&foo=199 so it preserve array ['1,2', '199'] instead of splitting it to ['1', '2', '199']

@pySilver
Copy link
Author

pySilver commented Nov 8, 2016

@carltongibson any feedback on this?

@carltongibson
Copy link
Owner

Yes. I'm think it looks good. It needs a doc entry for the widget.

Other than that I just need a moment to consider it fully.

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants