-
Notifications
You must be signed in to change notification settings - Fork 769
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
Add abstract CSV filters, filter overrides for specific lookup types #363
Conversation
This will allow us to correctly provide overrides for transformed lookups. eg, `published_at__year__gte=2016`
- sanitize does not allow for empty values - type conversion should happen at the field level
Conflicts: django_filters/filters.py
- Includes 'isnull' handling - Includes 'in' and 'range' handling that are dynamically created for its underlying field type.
@rpkilby This looks great. Just on your last point: I'm not too worried about caching. I'd be very surprised if we had a bottleneck here. (And I'm inclined to leave such things as out of scope.) |
Conflicts: django_filters/filters.py docs/usage.txt tests/test_filters.py tests/test_filterset.py
Hi @carltongibson. I think this is ready for review. My only outstanding concern is documentation. I have added docs for the base IN and RANGE filters, as well as doc updates for the shift from So, are more extensive docs necessary? While this is a somewhat large PR, it's really just one big bug fix for handling filter generation for some lookups. Maybe adding more detailed notes to the changelog would suffice? |
@rpkilby This is great.
What I'd really like to see here is just few lines demonstrating the usage of the (various) CSV options — by that I mean a snippet of the URL query string that the user constructs for the filtering behaviour and the matching filter declaration — i.e. we don't need running examples — but useful extracts. My main issue is that new users find it hard to see how to put filter sets together — that's a documentation thing — the learning curve is too steep. Makes sense? |
Conflicts: django_filters/filters.py tests/test_fields.py
This doesn't really seem appropriate for an introductory section on basic FilterSet usage.
@carltongibson I've added docs on a separate branch/self-PR because the changes are somewhat extensive. Similar to this PR, there's a bit going on so I tried to isolate the work done in each commit. Reading the history in order might give you a better idea of what's going on than looking at the whole diff at once.
Usage docs for the CSV filters are in this commit. This was based off of the
All of the other commits are an attempt at improving the structure and approachability of the docs. I don't know if that's achieved, but that was the idea. Please nitpick any issues or submit PRs against my fork or whatever. If all looks good, I'll merge the doc changes PR into this one so we can proceed. |
Also, added some notes on how to override |
Update documentation
Alright - docs are updated and merged. |
Quick note - improved handling for The |
Add abstract CSV filters, filter overrides for specific lookup types
👍 |
Sweet - any timeframe on the release? There are some updates to drf-filters that will be dependent on it. Thanks. |
This week. |
Great - thanks again. |
This is an old thread, but I just want to say how wonderful it was to find this feature available today, just when I needed it. Truly wonderful, thank you so much for all your efforts on this project. You've made at least one person super happy today. |
😊 |
This supersedes/builds on my last PR (#362). Here is the diff between the two.
Relevant issues:
Closes #362 (PR)
Closes #344 (PR)
Fixes #321
Fixes #273
Changes:
Filterset.filter_for_lookup
).The abstract CSV filter work is partially based on the work done in #344. The major difference is that type conversion/validation is performed by the field instead of in the widget's
customize
method. Dynamically created subclasses allow us to use the abstract CSV filter to handle just the list of values, while reusing theclean
ing behavior on individual values from the base field class. I also removedsanitize
, as it did not allow you to filter by empty char values.TODO:
This is not fully complete, but wanted to go ahead and try to get eyes on as it should be close to done.
Filterset.filter_for_lookup
)decide if dynamic CSV filters/fields should be cached (as twoNumberRangeFilter
classes would be identical). That said, it seems like a one time cost to generate the class then instance for each filter. Thoughts on this?