-
Notifications
You must be signed in to change notification settings - Fork 67
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
Contributing code - extending filter logic #47
Comments
Update: I have a nagging thought that this is all a bit too much, but anyway, I pushed an update that allows nesting lists as well as dictionaries, which means you can now express things like Comment.smart_query(filters=[{or_: {'x': 5, 'y': 6}}, {or_: {'z': 1, 'w': 2 }} ])
# where (x=5 or y=6) and (z=1 or w=2) See updated example for more details (If this is all possible already and I'm missing something fundamental please let me know : )) |
Hi Fred!
Thank you for your contribution to the code!
Would you mind creating a PR to the original repo?
…On Tue, Oct 20, 2020 at 1:25 PM Fred Ludlow ***@***.***> wrote:
Update: I have a nagging thought that this is all a bit too much, but
anyway, I pushed an update that allows nesting lists as well as
dictionaries, which means you can now express things like (X OR Y) AND (W
OR Z).
Comment.smart_query(filters=[{or_: {'x': 5, 'y': 6}}, {or_: {'z': 1, 'w': 2 }} ])# where (x=5 or y=6) and (z=1 or w=2)
See updated example
<https://github.com/fredludlow/sqlalchemy-mixins/blob/57a7a8f763ead72308c03b037385ba4bdff9b879/examples/smartquery.py#L418>
for more details
(If this is all possible already and I'm missing something fundamental
please let me know : ))
—
You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub
<#47 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AAMJAIYAMEKPJN7ENVCOEFLSLVQSZANCNFSM4SSRLOSA>
.
|
This was referenced Oct 21, 2020
Closed
This was referenced Jun 6, 2021
Merged
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hi,
I've been using sqlalchemy-mixins in a project recently and found it really useful. One thing I wanted to be able to do was to have more complex logic when filtering objects. To lift your example from the docs - show all posts that are either public or have no user.
I had a bit of a hack around and extended smart_query to take dictionaries of the form:
This seems to work well, though it's a bit ugly to use functions as dictionary keys and it only works with smart_query, not
where
if the function is at the top level (function kwargs need to be strings)I've got tests, docs etc. in my branch here: fredludlow/sqlalchemy-mixins@master...filter-operators
If you like it then I can make a PR. If you don't like it in its current state but can think of another good way to do this I'm all ears!
The text was updated successfully, but these errors were encountered: