Skip to content
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

Feature request: automatic filter negation/exclusion #978

Closed
aidanlister opened this issue Sep 21, 2018 · 5 comments
Closed

Feature request: automatic filter negation/exclusion #978

aidanlister opened this issue Sep 21, 2018 · 5 comments

Comments

@aidanlister
Copy link

This package supersedes django-rest-framework-filters, but django-rest-framework-filters had a great feature that allows you to do foo!=bar automatically (changes from a filter to an exclude).

https://github.com/philipn/django-rest-framework-filters#automatic-filter-negationexclusion
https://github.com/philipn/django-rest-framework-filters/pull/43/files

This is a nice saving, all of our filtersets look like this:

    text_contains = SearchFilter(fields=['property__name', 'property__client_ref', 'compliancetype__name'], comparison='contains')
    text_excludes = SearchFilter(fields=['property__name', 'property__client_ref', 'compliancetype__name'], comparison='excludes')
    ref_contains = SearchFilter(fields=['property__client_ref'], comparison='contains')
    ref_excludes = SearchFilter(fields=['property__client_ref'], comparison='excludes')
    property_contains = SearchFilter(fields=['property__name'], comparison='contains')
    property_excludes = SearchFilter(fields=['property__name'], comparison='excludes')
    category_contains = SearchFilter(fields=['compliancetype__name'], comparison='contains')
    category_excludes = SearchFilter(fields=['compliancetype__name'], comparison='excludes')

Would you accept a PR that included this functionality?

@zkne
Copy link

zkne commented Jul 23, 2019

This feature is much needed!

@carltongibson
Copy link
Owner

I have no real desire to expand the API of django-filter. (I'm not in favour of automatically extending the filters available: these drive your database, you want to control them.)

However, as I understand it, django-rest-framework-filters just builds on django-filter, so if you like its features, why not just use it?

@rpkilby What is the state of play here? (Thanks!)

@carltongibson
Copy link
Owner

carltongibson commented Jul 24, 2019

Also, looking at the diff from the linked PR there, isn't a FilterSet subclass (or decorating class, in the GOF sense) available without too much effort?

@rpkilby
Copy link
Collaborator

rpkilby commented Jul 26, 2019

What is the state of play here?

It's a little complicated. Automatic negation works for most cases, however it runs into issues with multi-valued relationships (see: philipn/django-rest-framework-filters#217). But in general, django-filter doesn't really handling to-many relationships well (#745, #1077), so maybe it should be considered out-of-scope, punting to drf-filters?


I have no real desire to expand the API of django-filter.

I would agree against expanding the API of the base FilterSet. Automatic negation is a somewhat "magical" feature, and if django-filter were to support it, it should exist as a mixin.

@carltongibson
Copy link
Owner

Okay, thanks @rpkilby. I’m going to close. Don’t mind seeing examples from users but not ready to include, even as a mixin, at this point.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants