fastapi-filter icon indicating copy to clipboard operation
fastapi-filter copied to clipboard

Filter methods

Open foarsitter opened this issue 2 years ago • 9 comments

When I'm filtering on an amount I want to include null values. This involves an or_.

I modified the filter method so it checks if there is a filter method defined, i.e:

class ProductFilter(Filter):
    costs__lte: int | None = Field(None)

    def filter_costs__lte(self, value: Any, query: Union[Query, Select]) -> Union[Query, Select]:
        return query.filter(
            or_(
                Product.costs <= value,
                Product.costs == null()
            )
        )

I can provide a PR when this is the way you want to go.

Thanks for providing this library!

foarsitter avatar Jan 12 '24 08:01 foarsitter

This issue is stale because it has been open 60 days with no activity. Remove stale label or comment or this will be closed in 5 days.

github-actions[bot] avatar Apr 09 '24 01:04 github-actions[bot]