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

How to filter an array field #556

Open
raphodn opened this issue Feb 21, 2024 · 5 comments
Open

How to filter an array field #556

raphodn opened this issue Feb 21, 2024 · 5 comments

Comments

@raphodn
Copy link

raphodn commented Feb 21, 2024

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 :)

@verhovensky
Copy link

Also interested

@raphodn
Copy link
Author

raphodn commented Apr 8, 2024

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

Copy link

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 github-actions bot added the Stale label Sep 27, 2024
@waza-ari
Copy link

waza-ari commented Oct 2, 2024

Also interested in that, it would be a shame if it gets closed unnoticed.

@arthurio arthurio removed the Stale label Oct 2, 2024
@verhovensky
Copy link

@raphodn
Same for me, but having more than 5 such fields seems overwhelming due to not much changing logic which seems to disrupt DRY principle

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

No branches or pull requests

4 participants