Skip to content
Snippets Groups Projects
Commit edf2cf78 authored by Konrad Mohrfeldt's avatar Konrad Mohrfeldt :koala:
Browse files

feat: add new syntaxes for filtering by choices

In addition to the

	?foo=1,2,3

filter syntax we now also support

	?foo=1&foo=2&foo=3
	?foo[]=1&foo[]=2&foo[]=3
parent b82b0435
No related branches found
No related tags found
1 merge request!21Add API documentation
......@@ -20,8 +20,19 @@ class StaticFilterHelpTextMixin:
class ModelMultipleChoiceFilter(filters.ModelMultipleChoiceFilter):
class QueryArrayWidget(widgets.QueryArrayWidget):
# see: https://github.com/carltongibson/django-filter/issues/1047
def value_from_datadict(self, data, files, name):
new_data = {}
for key in data.keys():
if len(data.getlist(key)) == 1 and "," in data[key]:
new_data[key] = data[key]
else:
new_data[key] = data.getlist(key)
return super().value_from_datadict(new_data, files, name)
def __init__(self, *args, **kwargs):
kwargs.setdefault("widget", widgets.CSVWidget())
kwargs.setdefault("widget", self.QueryArrayWidget())
kwargs["lookup_expr"] = "in"
super().__init__(*args, **kwargs)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment