-
Notifications
You must be signed in to change notification settings - Fork 768
Open
Description
Bug
The docs state that TypedChoiceFilter is the same as ChoiceFilter with an additional coerce argument https://django-filter.readthedocs.io/en/stable/ref/filters.html#typedchoicefilter. However, null_value and null_label are not acceptable arguments to TypedChoiceFilter.
Example snippet + error message
myboolean = filters.TypedChoiceFilter(
choices=(
("yes", "Yes"),
("no", "No"),
),
coerce=lambda x: x == "yes",
null_label="Unknown",
null_value="null",
field_name="myboolean",
)
TypeError: Field.__init__() got an unexpected keyword argument 'null_label'
Relevant django-filters code
The following snippet implements the null lookup as best I can tell. It is implemented directly on the ChoiceFilter so is not shared with the TypedChoiceFilter (which does not inherit from ChoiceFilter).
django-filter/django_filters/filters.py
Lines 186 to 193 in 635343e
def filter(self, qs, value): | |
if value != self.null_value: | |
return super().filter(qs, value) | |
qs = self.get_method(qs)( | |
**{"%s__%s" % (self.field_name, self.lookup_expr): None} | |
) | |
return qs.distinct() if self.distinct else qs |
Metadata
Metadata
Assignees
Labels
No labels