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

Add support for passing a method to filters generated through AutoFilter #329

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

RouganStriker
Copy link

Allow AutoFilter to accept a method param and pass it to the generated filters.

The same behaviour for the following

class MyFilter(FilterSet):
    title__contains = CharFilter(method='custom_pk_filter')
    title__endswith = CharFilter(method='custom_pk_filter')

    def custom_pk_filter(self, qs, field, value):
        pass

Can now be done as

class MyFilter(FilterSet):
    title = AutoFilter(lookups=['contains', 'endswith'], method='custom_pk_filter')

    def custom_pk_filter(self, qs, field, value):
        pass

@rpkilby
Copy link
Collaborator

rpkilby commented Mar 25, 2020

Thanks for submitting this. For now, this is blocked by carltongibson/django-filter#1150, which would make the field_name/lookup_expr workaround unnecessary.

@rpkilby rpkilby mentioned this pull request Aug 8, 2020
@SunnyR SunnyR deleted the tech/pas/198_drf_filters branch June 7, 2024 03:33
@codecov-commenter
Copy link

⚠️ Please install the 'codecov app svg image' to ensure uploads and comments are reliably processed by Codecov.

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 99.71%. Comparing base (a6fc693) to head (9a3cfa3).
Report is 10 commits behind head on master.

❗ Your organization needs to install the Codecov GitHub app to enable full functionality.

Additional details and impacted files

Impacted file tree graph

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

Successfully merging this pull request may close these issues.

3 participants