From 3676052ed384a3b8b8fe894849efaa9c7f5f1340 Mon Sep 17 00:00:00 2001 From: Anna Shamray Date: Thu, 12 Dec 2024 14:46:44 +0100 Subject: [PATCH] :green_heart: [#472] fix new filter field widget --- src/objects/tests/v2/test_filters.py | 1 - src/objects/utils/filters.py | 4 ++++ 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/src/objects/tests/v2/test_filters.py b/src/objects/tests/v2/test_filters.py index 684b3da8..19c714fe 100644 --- a/src/objects/tests/v2/test_filters.py +++ b/src/objects/tests/v2/test_filters.py @@ -500,7 +500,6 @@ def test_filter_two_icontains_with_comma(self): ) - class FilterDateTests(TokenAuthMixin, APITestCase): @classmethod def setUpTestData(cls): diff --git a/src/objects/utils/filters.py b/src/objects/utils/filters.py index 14555b76..0f19187c 100644 --- a/src/objects/utils/filters.py +++ b/src/objects/utils/filters.py @@ -53,6 +53,9 @@ class ObjectTypeFilter(URLModelChoiceFilter): class ManyWidget(forms.Widget): def value_from_datadict(self, data, files, name): + if name not in data: + return [] + return data.getlist(name) @@ -69,4 +72,5 @@ def to_python(self, value): class ManyCharFilter(filters.CharFilter): # django-filter doesn't support several uses of the same query param out of the box + # so we need to do it ourselves field_class = ManyCharField