I want to be able to accept a list query param using the standard application/x-www-form-urlencoded
format, as stated in https://stackoverflow.com/a/9176496/4650346. For example to filter products by a list of categories, I would like to use:
http://my.api.com/products?category[]=shirts&category[]=sweaters
I can create a FilterSet that acomplish this multiple choice filtering, the issue is that it won't follow the standard as I am unable to add the suffix []
that express it is a list. The following class demonstrates the functionality that I need.
class MyFilter(django_filters.FilterSet):
category = django_filters.ModelMultipleChoiceFilter(
queryset=Category.objects.all(),
name='categories'
)
class Meta:
model = MyModel
fields = ['category',]
That code, will allow users to create requests as:
http://my.api.com/products?category=shirt&category=sweaters
Question is: how can I add the suffix []
to the GET parameters that represent a list in the URI?
Cheers,