Skip to content

Commit cf2635f

Browse files
committed
fix non-strict filter bug introduced in last commit
1 parent 1d18843 commit cf2635f

File tree

1 file changed

+10
-3
lines changed

1 file changed

+10
-3
lines changed

src/django_enum/filters.py

+10-3
Original file line numberDiff line numberDiff line change
@@ -58,12 +58,15 @@ class Color(TextChoices):
5858
"""
5959

6060
enum: t.Type[Enum]
61+
strict: bool
6162
field_class = EnumChoiceField
6263

63-
def __init__(self, *, enum: t.Type[Enum], **kwargs):
64+
def __init__(self, *, enum: t.Type[Enum], strict: bool = True, **kwargs):
6465
self.enum = enum
66+
self.strict = strict
6567
super().__init__(
6668
enum=enum,
69+
strict=strict,
6770
choices=kwargs.pop("choices", choices(self.enum)),
6871
**kwargs,
6972
)
@@ -85,18 +88,22 @@ class MultipleEnumFilter(TypedMultipleChoiceFilter):
8588
"""
8689

8790
enum: t.Type[Enum]
91+
strict: bool
8892
field_class = EnumMultipleChoiceField
8993

9094
def __init__(
9195
self,
9296
*,
9397
enum: t.Type[Enum],
98+
strict: bool = True,
9499
conjoined: bool = False,
95100
**kwargs,
96101
):
97102
self.enum = enum
103+
self.strict = strict
98104
super().__init__(
99105
enum=enum,
106+
strict=strict,
100107
choices=kwargs.pop("choices", choices(self.enum)),
101108
conjoined=conjoined,
102109
**kwargs,
@@ -126,8 +133,8 @@ def __init__(
126133
self,
127134
*,
128135
enum: t.Type[Flag],
136+
strict: bool = True,
129137
conjoined: bool = False,
130-
strict: bool = False,
131138
**kwargs,
132139
):
133140
self.enum = enum
@@ -165,7 +172,7 @@ class FilterSet(filterset.FilterSet):
165172

166173
@staticmethod
167174
def enum_extra(f: EnumField) -> t.Dict[str, t.Any]:
168-
return {"enum": f.enum, "choices": f.choices}
175+
return {"enum": f.enum, "strict": f.strict, "choices": f.choices}
169176

170177
FILTER_DEFAULTS = {
171178
**{

0 commit comments

Comments
 (0)