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

Overriding FilteringFilterBackend.filter_queryset #312

Open
selimt opened this issue Oct 2, 2023 · 0 comments
Open

Overriding FilteringFilterBackend.filter_queryset #312

selimt opened this issue Oct 2, 2023 · 0 comments
Labels

Comments

@selimt
Copy link

selimt commented Oct 2, 2023

Questions

Is there a way to override filter_queryset in FilteringFilterBackend without having to copy all the code to the inheriting class?

I want to add support for the match_phrase operator but because the conditional defaults to the term filter like in here:

                # `term` filter lookup. This is default if no `default_lookup`
                # option has been given or explicit lookup provided.
                else:
                    queryset = self.apply_filter_term(queryset,
                                                      options,
                                                      value)

I end up with a query like this which doesn't work:

query":{"bool":{"filter":[{"term":{"name":"running"}}],"must":[{"match_phrase":{"name.trigram":"running"}}]}}

My apply method is as follows:

        return self.apply_query(
            queryset=queryset,
            options=options,
            args=[Q("match_phrase", **{"{}.trigram".format(options['field']): value})]
        )

Thanks.
-Selim

@selimt selimt added the question label Oct 2, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant