Skip to content

Overriding FilteringFilterBackend.filter_queryset #312

Open
@selimt

Description

@selimt

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions