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
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.

None yet

2 participants