Issue 8: get_depth (or get_level)
Status:  Verified
Owner: ----
Closed:  Sep 2010
Reported by peac...@gmail.com, Jan 11, 2008
Type: Enhancement
Priority: medium

Hi,

I want to suggest these functions to be added to the model and manager
interface:

1. model.get_depth() : the depth of this node from root node
2. model.get_level() : alias for get_depth
2. manager.get_depth(tree_id) : the depth from the root node to the lowest
leaf node
 
Thank you.
Jan 14, 2008
Project Member #1 jonathan.buchanan
How about using the .level field available on each model instance?

1 & 2: some_instance.level

Can you give an example of what you would use the total depth of the tree for? If
there's some useful tree functionality which adding this method to the manager would
enable, we could look at seeing how much of that could go in MPTT.
Status: Chatting
Labels: -Type-Defect Type-Enhancement
Jan 14, 2008
#2 peac...@gmail.com
Hi,

Sure we can use the level field but the user'd need to look at the code first to know
that there is a level field. Even so the level field is abstracted in level_attr, so
it's name is not fixed.

For case when we need the depth of the tree, an example is when we want to print the
whole tree and we want to reserve the width of the column.

Thanks.
Dec 5, 2008
#3 mocksoul
get_level() should be nice!

For example, I have tuned column names and use `mptt_level`, `mptt_left`, etc. 
instead of `level` and `lft`. Thus, for me it may be much better to use get_level() 
not depending on column names.
Sep 2, 2010
Project Member #4 craig.ds@gmail.com
Added node.get_level() in http://github.com/django-mptt/django-mptt/commit/c1ee708ae8fdd377537dd5c180aec5a8ddca1490

Total depth of tree is a slow operation and I can't see it being useful in very many scenarios. Wont fix that for now.
Status: Verified