feincms/django-tree-queries

Is returning nodes in breadth-first order possible

atodorov opened this issue · 2 comments

I want to generate a nested HTML list structure and the easiest way would be to have the tree nodes sorted in BFS order. Or be able to .order_by('tree_depth') on the resulting query.

Instead I can call .order_by('__tree.tree_depth') but that seems to have no effect.

The tree_* fields aren't known to the Django query machinery and therefore cannot be used with .order_by() unfortunately. You have to go through the .extra() API. I added a test here which demonstrates a hopefully correct BFS ordering: 1f14410

Thanks for the tip & the test. That works for me.