-
-
Notifications
You must be signed in to change notification settings - Fork 27
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
Add the ability to filter queries before construction of the CTE #66
Conversation
* Update query.py Add `pre_filter` and `pre_exclude` methods to TreeQuerySet. Make query methods call `_setup_query` to deal with sibling order and pre_filter persistence issues. * Update compiler.py Replace the `get_sibling_order_params` with `get_rank_table_params` to support early tree filtering. Change `sibling_order` and `pre_filter` from class variables to variables that have to be initiated by `_setup_query` so that they don't persist between user queries. Handle pre_filter params by passing them to the django backend. * Update test_queries.py Added tests for the `pre_filter` and `pre_exclude` methods.
This addresses issue #50 and also addresses a possible bug where sibling ordering was persisting between queries even when no explicit ordering was given because it was being stored as a class variable. It should be noted that filtering prior to the construction of the CTE means that filtered status is inherited i.e. if a parent is excluded so too will all of its descendants. This contrasts with a normal filter which when applied after the CTE is built will retain the descendants of an excluded parent if those descendants meet the filtering criteria. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks! I like the functionality and it makes a lot of sense to me.
I wonder if something like tree_filter
wouldn't be a better name for this? Also, I'd prefer using Q
objects here.
.tree_filter(~Q(name="2-2"))
would replace .pre_exclude(name="2-2")
, and .tree_filter(Q(name__in=[...]))
would replace .pre_filter(name__in=[...])
. Or do you see a reason why that would be worse? I think using Q
objects directly would simplify the filtering code by a relevant amount.
If you think I had completely forgotten about |
Change `pre_filter` to `tree_filter` and add support for `Q` objects
I had an idea for how to simplify this feature by making the Django ORM generate the entire |
* Update compiler.py & query.py Generate the rank_table entirely with django's backend by providing a queryset instance variable that can be modified by the API
I've simplified the code by adding the instance variable called |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the reminder! I'm not working this week and have been a bit stressed out last week, so I have forgotten about this.
Using the query is an excellent idea!
Add django version checking to back compat code
Remove Python 2 support and use SimpleNamespace
Thank you! |
Update query.py
-Add
pre_filter
andpre_exclude
methods to TreeQuerySet.-Make query methods call
_setup_query
to deal with sibling order and pre_filter persistence issues.Update compiler.py
-Replace the
get_sibling_order_params
withget_rank_table_params
to support early tree filtering.-Change
sibling_order
andpre_filter
from class variables to variables that have to be initiated by_setup_query
so that they don't persist between user queries.-Handle pre_filter params by passing them to the django backend.
Update test_queries.py
-Added tests for the
pre_filter
andpre_exclude
methods.