feat: Django-style filtering system (#52) - #54
Merged
Conversation
Implements a robust filtering system (#52) for the admin API and UI following django-filter conventions: - New lookups: icontains, startswith, endswith, gt, gte, lt, lte, range and in, on top of exact matches and legacy from/to. - New ChoiceFilter auto-registered for FK/ManyToMany columns; numeric filters gain full comparison lookups. - Shared lookup parsing in filters/lookups.py used by both the HTML list views and the JSON API. - ORM-agnostic: QueryBackend gains and_; in-memory backend now handles %-anchored ilike patterns. - Admin UI renders icontains input for text fields and min/max inputs for numeric fields. - Docs, changelog, and 33 new tests (unit + API + in-memory + UI).
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
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 #52
Summary
Implements a robust, ORM-agnostic filtering system for the admin API and admin UI list views, following Django's
django-filterconventions.Lookup types added
?filter_name=value— exact match (existing)?filter_name__icontains=term— case-insensitive contains?filter_name__startswith=Jo/__endswith=hn?filter_price__gt=100/__gte/__lt/__lte?filter_price__range=10,200— inclusive range?filter_id__in=1,2,3— in list__from/__torange params still supportedFilter classes
TextFilter— exact + icontains/startswith/endswithChoiceFilter— new, for relation/FK fields, rendered as a select (auto-detected inFilterRegistry.auto_generate())IntegerFilter/NumericFilter— gt/gte/lt/lte/range/inDateRangeFilter/DatetimeRangeFilter/TimeFilter— comparison + range + inBooleanFilter/EnumFilter— with choicesRelationFilterkept as a backwards-compatible alias ofChoiceFilterORM-agnostic
QueryBackendprotocol;QueryBackendgains anand_combinator (added to SQLAlchemy + memory backends).%-anchoredilikepatterns (startswith/endswith/contains).Admin UI
__icontainstext input.__gte) / Max (__lte) inputs.filters/lookups.py) is used by both the HTML list views and the JSON API.Tests
33 new tests: lookup parsing, per-filter clause building, registry auto-detection (SQLAlchemy + memory), JSON API end-to-end for every lookup, admin UI list-view filtering, and in-memory backend lookups. Full suite: 879 passed.
Docs
Updated
docs/guide/filters.md,docs/guide/features.md, andCHANGELOG.md.