Django-filter: MultipleChoiceFilter with empty square brackets

Created on 25 Jan 2019  路  6Comments  路  Source: carltongibson/django-filter

Can I create a PHP style MultipleChoiceFilter field?
?field[]=var1&field[]=var2

Most helpful comment

All 6 comments

That's the default.

The default is ?field=var1&field=var2 not ?field[]=var1&field[]=var2.

Ah, I see... One way: You could use custom widget to affect the input rendering (to add the [] to the name attribute)

You'll have to decide if it's what you want though:

>>> from django.http.request import QueryDict
>>> GET = QueryDict('field[]=var1&field[]=var2')
>>> GET
<QueryDict: {'field[]': ['var1', 'var2']}>

(You end up with the [] on the field name for the incoming data too.)

Ah, yes. Well done! There's already a widget. Great.

(I was sure we'd had this conversation before... 馃檪)

thks!!!!!

Was this page helpful?
0 / 5 - 0 ratings