You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
How should it look?
I have a tree below the selected node (for example node 7). Result looks like a python dictionary because the dictionary also has a tree structure. As a request, I can only display a flat structure and writing such a request is very simple dbsession.query(Tree).filter(Tree.left > node7.left).filter(Tree.right < node7.right)
My idea looks like this. The current drill down tree returns a python dictionary, but if it can return a query set like how it list ancestor nodes, it will only read all data from the database when the data is finally needed, which not only makes The api looks more user-friendly and avoids unnecessary read operations. You can also use the api of the query set in sqlalchemy instead of writing a python dictionary-based query
This may lead to multiple queries in some scenarios, but the performance is much better than reading all grandchildren nodes. Of course, it is possible to query directly using the left and right fields, but I will be happy if it is in node's methods.
Allright, in current version, we use Drilldown like this:
Drilldown
Drilldown tree for a given node.
A drilldown tree consists of a node’s ancestors, itself and its immediate children. For example, a drilldown tree for a foo1 category might look something like:
Drilldown for foo1 node
level
1 1(root)14
|
---------------------
| ----------|---------------
2 2(foo)7 | 8(foo1)13 |
| | / \ |
3 3(bar)6 | 9(bar1)10 11(baz1)12 |
| --------------------------
4 4(baz)5
categories = Category.query.all()
for item in categories:
print(item)
pprint(item.drilldown_tree())
print()
Path to root return a sqlalchemy query set, so if you finally need the nodes, you should first call .all() method, another usage is to call .fliter() for further query. For drilldown, it's common to make some further query. Otherwise, we need to write filter in python not queries in database.
So maybe there should be a new method for mptt node to get a query object which includes all children nodes, and drilldown should be kept to get the tree structure.
So maybe there should be a new method for mptt node to get a query object which includes all children nodes, and drilldown should be kept to get the tree structure.
Activity
uralbash commentedon Aug 5, 2020
How should it look?
I have a tree below the selected node (for example node 7). Result looks like a python dictionary because the dictionary also has a tree structure. As a request, I can only display a flat structure and writing such a request is very simple dbsession.query(Tree).filter(Tree.left > node7.left).filter(Tree.right < node7.right)
ODtian commentedon Aug 5, 2020
My idea looks like this. The current drill down tree returns a python dictionary, but if it can return a query set like how it list ancestor nodes, it will only read all data from the database when the data is finally needed, which not only makes The api looks more user-friendly and avoids unnecessary read operations. You can also use the api of the query set in sqlalchemy instead of writing a python dictionary-based query
ODtian commentedon Aug 5, 2020
This may lead to multiple queries in some scenarios, but the performance is much better than reading all grandchildren nodes. Of course, it is possible to query directly using the left and right fields, but I will be happy if it is in node's methods.
uralbash commentedon Aug 6, 2020
Could you give an example of how this should look? What should the function return?
ODtian commentedon Aug 6, 2020
Allright, in current version, we use Drilldown like this:
So what it return is a python dict and the nodes are already listed.
How path to root work:
Path to root return a sqlalchemy query set, so if you finally need the nodes, you should first call
.all()method, another usage is to call.fliter()for further query. For drilldown, it's common to make some further query. Otherwise, we need to write filter in python not queries in database.ODtian commentedon Aug 6, 2020
I mean Query object in sqlalchemy, query set is the orm query object in Django
ODtian commentedon Aug 6, 2020
So maybe there should be a new method for mptt node to get a query object which includes all children nodes, and drilldown should be kept to get the tree structure.
uralbash commentedon Aug 7, 2020
I will think about how to do it