fastapi-filter
fastapi-filter copied to clipboard
How to filter an array field
Hi !
I'm struggling to understand if/how I can filter an array field.
I'm using SQLAlchemy + PostgreSQL, and I have a Product.categories_tags
field that looks like this : ["en:beverages", "en:orange-juices]
.
I would like to be able to filter this field in a simple manner, for example : categories_tags__contains=en:beverages
Is this something feasible ? a possible linked PR : #395
Thanks in advance for your help, I'd be willing to do a PR if needed :)
Also interested
Fyi, I ended up managing the filtering myself
- adding
categories_tags__contains: Optional[str] | None = None
in my filter class - and having a custom filter in the crud
if filters.categories_tags__contains:
query = query.filter(Product.categories_tags.contains([filters.categories_tags__contains]))
filters.categories_tags__contains = None
see this PR changes : https://github.com/openfoodfacts/open-prices/pull/234/files
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.