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
roadmap for django-filter #75
Comments
Are there plans to add a search filter (similar to what the admin provides) ? |
Thanks for the question @xordoquy. Search in the admin, for def construct_search(field_name):
if field_name.startswith('^'):
return "%s__istartswith" % field_name[1:]
elif field_name.startswith('='):
return "%s__iexact" % field_name[1:]
elif field_name.startswith('@'):
return "%s__search" % field_name[1:]
else:
return "%s__icontains" % field_name The net result is a fairly comprehensive, yet flexible, search. |
Here's an example for the Q object refactor thoughts above. Given: an # If you query a User for first_name and last_name
User.objects.filter(first_name='John', last_name='Smith')
# finds Users with first_name of John AND last_name of Smith
# If you chain the request (like django-filter would)
User.objects.filter(first_name='John').filter(last_name='Smith')
# finds Users with first_name of John AND last_name of Smith
# But, if you query an Article by the reporter's first_name and last_name
Article.objects.filter(reporter__first_name='John', reporter__last_name='Smith')
# finds Articles reported by a User with first_name of John AND last_name of Smith
# If you chain the request (like django-filter would)
Article.objects.filter(reporter__first_name='John').filter(reporter__last_name='Smith')
# finds Articles reported by a User with first_name of John OR last_name of Smith
# But, using Q objects and filtering the join of them will work for both
Article.objects.filter(Q(reporter__first_name='John'), Q(reporter__last_name='Smith'))
# finds Articles reported by a User with first_name of John AND last_name of Smith |
wow @nkryptic, looks like django-filter does have quite a future ahead of it :) Can't see anything where I'd object, keep the pull requests coming! |
django-easyfilters is shares a lot of core concepts with django-filter, but provides a much more functional version of the limited LinkWidget we have in this project. Would you have any issue with me starting a conversation with Luke Plant (maintainer of django-easyfilters) about the possibility of merging the two projects functionality? |
Sounds fine to me. |
I've just build a simple SearchFilter which works with django-filter. It uses the django admin query builder so should deliver the same functionality. https://gist.github.com/olivergeorge/5088386 (One slight hack is I've set the filter name to point at 'pk' since this is effectively a multifield filter and the system doesn't seem to handle that well). |
Thanks for the comments and the gist. I worked out something similar: I was looking for extensibility, which declaring the I've been toying with attempts to make it more generic, so that a MultiFieldFilter could be used as the base for a StringSearchFilter or even a DateSearchFilter (where different lookup types would make sense). |
Looks good.
|
@carltongibson Can you turn the original issue into a TODO list so we'll know what's implemented and what's not yet? |
Hey @omerzimp (did you change your account?) TBH I'm not far off closing this ticket as stale/inactionable (take your pick). The reason I haven't done so already is that there are a number of ideas and I want to make sure I've grasped them before moving on. As far as I'm concerned the Roadmap looks like:
There is no 3. |
@carltongibson No I didn't change my account. I commented from my workplace's account by mistake :P |
Is there MultiFieldFilter or similar functionality in django-filter for now? |
@lampslave open a new issue, describing what you're looking for, and we'll discuss there |
@carltongibson MultiFieldFilter is already described and discussed on this page, but I couldn't see it in the docs and code :( |
I think this project is great and extremely useful. But, I also think there are a few things to add, improve on, or remove which could make it even greater. I'm putting this together to determine what to focus on next and into the future.
I wanted to give an overview of all the items, so they can be thought through as a whole. I didn't want to just throw a bunch of individual issues up, since a few of the items relate to multiple existing issues and it makes it difficult to see the big picture.
With some feedback on what to pursue and a few design decisions, I'll be happy to start tackling them.
In no particular order:
overhaul and expand documentation
It's fairly spartan right now. A few things I'd like to see:
overhaul and expand test suite
I don't think there are any tests which cover ModelMultipleChoiceFilter there might be other large holes in the test coverage. A few things I'd like to see:
replace RangeFilter and DateRangeFilter
These filters are limited.
addresses #48 and one of the commits from #41
make declaring 'Choice' filters easier
allow for easier overriding of certain attributes without having to restate everything.
choices
from model field on a declared ChoiceFilter and MultipleChoiceFilter when not providedfilter_for_field
when the field has choices - addresses issue Error with ChoiceFiter and ManyToOneRel #30queryset
on declared ModelChoiceFilter and ModelMultipleChoiceFilter when not providedfilter_for_field
with theextra
s - similar to issue Error with ChoiceFiter and ManyToOneRel #30to_field_name
also for ModelChoiceFilterimprove ChoiceFilter, MultipleChoiceFilter and AllValuesFilter
any
option to choices, which is definitely missing - addresses issues AllValuesFilter does not have an empty value #36, Bug in M2M Filter #41 and Add "Any" filter to ChoicesField #45allow filtering of non-required fields for BLANKs
It currently almost impossible to filter for records that haven't been assigned a value
blank
optionpossibly related to issue #41
allow for 'AND'ing a ModelMultipleChoiceFilter's selected values
e.g. find all Articles tagged 'django' AND 'filter' - addresses issue #24
easier overriding of widgets used
when using a non-declared filter, but you want a different widget - see issue #25
widgets
attribute to FilterSet.Meta class?improve order_by
order_by=True
is useddetermine a future for LinkWidget
should it ever be used in a filterset with other filters that aren't using LinkWidget?
add MultiFieldFilter (or just MultiFieldCharFilter)
single form field and the value is checked against multiple model fields (join with 'OR' )
I have created a gist to act as a proof of concept for this: https://gist.github.com/nkryptic/4727865
refactor filters to use Q objects
fairly substantial change, since it will change the
Filter.filter
method's call signature to no longer pass the queryset.the only downside I can come up with is if the user is using a custom queryset with helper methods, it won't be possible to use them in a custom filter like you could when passing the queryset to each filter's filter method. I don't know how big an impact that would have.
The text was updated successfully, but these errors were encountered: