-
Notifications
You must be signed in to change notification settings - Fork 2.9k
Closes #7604: Add filter modifier dropdowns for advanced lookup operators #20747
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
Open
jnovinger
wants to merge
15
commits into
feature
Choose a base branch
from
7604-filter-modifiers-v4
base: feature
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+1,149
−125
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Implements dynamic filter modifier UI that allows users to select lookup operators (exact, contains, starts with, regex, negation, empty/not empty) directly in filter forms without manual URL parameter editing. Supports filters for all scalar types and strings, as well as some related object filters. Explicitly does not support filters on fields that use APIWidget. That has been broken out in to follow up work. **Backend:** - FilterModifierWidget: Wraps form widgets with lookup modifier dropdown - FilterModifierMixin: Auto-enhances filterset fields with appropriate lookups - Extended lookup support: Adds negation (n), regex, iregex, empty_true/false lookups - Field-type-aware: CharField gets text lookups, IntegerField gets comparison operators, etc. **Frontend:** - TypeScript handler syncs modifier dropdown with URL parameters - Dynamically updates form field names (serial → serial__ic) on modifier change - Flexible-width modifier dropdowns with semantic CSS classes
d1930b8 to
cebb92b
Compare
cebb92b to
5913ea8
Compare
Enable filter modifiers for single-choice ChoiceFields in addition to the existing MultipleChoiceField support. ChoiceFields can now display modifier dropdowns with "Is", "Is Not", "Is Empty", and "Is Not Empty" options when the corresponding FilterSet defines those lookups. The mixin correctly verifies lookup availability against the FilterSet, so modifiers only appear when multiple lookup options are actually supported. Currently most FilterSets only define 'exact' for single-choice fields, but this change enables future FilterSet enhancements to expose additional lookups for ChoiceFields.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Closes: #7604
Implements dynamic filter modifier UI that allows users to select lookup operators (exact, contains, starts with, regex, negation, empty/not empty) directly in filter forms without manual URL parameter editing.
Supports filters for all scalar types and strings, as well as some related object filters. Explicitly does not support filters on fields that use
APIWidget. That has been broken out in to follow up work.How It Works
Details
Backend:
FilterModifierWidgetWraps any Django form widget with a modifier dropdown. Key method:
This allows the widget to find its value regardless of which lookup modifier is active in the URL.
Backend:
FilterModifierMixinAutomatically enhances filterset form fields based on their type:
CharField->exact,contains(ic),startswith(isw),endswith(iew),iexact(ie),negation(n),regex,iregex,emptyIntegerField->exact,gte,lte,gt,lt,negation(n),emptyDecimalField->exact,gte,lte,gt,lt,negation(n),emptyDateField->exact,gte,lte,gt,lt,negation(n),emptyChoiceField->exact,negation(n),emptyMultipleChoiceField->exact,negation(n),emptyModelChoiceField->exact,negation(n),emptyColorField->exact,negation(n),emptyTagFilterField->exact,negation(n),emptyFrontend:
filterModifiers.tsTypescript handler that:
nameattributeFilter Pills Enhancement
Modified
applied_filterstemplate tag to:serial__ic)Scope & Compatibility
What's changed:
FilterFormsubclasses now have modifier dropdowns__ic,__n, etc.)What's NOT changed:
FilterSetbehavior unchanged