-
Notifications
You must be signed in to change notification settings - Fork 2.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closes: #17575 - Add NullableMultipleChoiceFilter and filter form UI to match empty string #17576
base: develop
Are you sure you want to change the base?
Changes from all commits
2c9eeb8
05ee5a5
98ba553
4f9e7db
1c6ee01
702b4df
240ab4e
c2473e6
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -18,6 +18,7 @@ | |
'MultiValueTimeFilter', | ||
'MultiValueWWNFilter', | ||
'NullableCharFieldFilter', | ||
'NullableMultipleChoiceFilter', | ||
'NumericArrayFilter', | ||
'TreeNodeMultipleChoiceFilter', | ||
) | ||
|
@@ -143,6 +144,16 @@ def filter(self, qs, value): | |
return qs.distinct() if self.distinct else qs | ||
|
||
|
||
class NullableMultipleChoiceFilter(django_filters.MultipleChoiceFilter): | ||
""" | ||
Similar to NullableCharFieldFilter, but allows multiple values including the special NULL string. | ||
""" | ||
def filter(self, qs, value): | ||
if settings.FILTERS_NULL_CHOICE_VALUE in value: | ||
value.append('') | ||
return super().filter(qs, value) | ||
Comment on lines
+151
to
+154
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It feels like we need to further consider the implications of storing empty strings rather than null values for these fields. django-filter has native support for the later; replacing empty strings with |
||
|
||
|
||
class NumericArrayFilter(django_filters.NumberFilter): | ||
""" | ||
Filter based on the presence of an integer within an ArrayField. | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This addresses the
type
field on Cable specifically, but I think what we need is a general implementation which covers all non-required choice fields, across all models. Ideally, this should be handled automatically for all model fields with achoices
attribute defined, which would obviate the need to manually declare these on the FilterSets as we currently do. (Granted, I'm not sure whether that's feasible.)