Changes between Initial Version and Version 1 of ModifiedPreorderTreeTraversalInAdmin


Ignore:
Timestamp:
Mar 10, 2006, 6:44:18 PM (19 years ago)
Author:
[530]
Comment:

Experimental

Legend:

Unmodified
Added
Removed
Modified
  • ModifiedPreorderTreeTraversalInAdmin

    v1 v1  
     1Looking at the mptt example [http://code.djangoproject.com/wiki/ModifiedPreorderTreeTraversal] it seemed a bit complicated for a normal user to understand. So i made my own, but considering i cannot group by makes aggregate functions hard (impossible?) to make this work nice, but magic-removal made it easier. But, here it is mostly . Use at will and own RISK, but if/ when you improve it i would like to see it made available.
     2
     3I attach the file and give a example here. Just add fields to this and in should work.
     4
     5Example using project name myproject and app name pages.
     6
     7{{{
     8
     9from myproject.pages.models import Page
     10
     11tree = Page.manager.all() # get entire tree
     12
     13parent = Page.manager.get(pk=10) # get object you want to get the children of
     14children = parent.get_children() # returns empty dict if no children are found
     15
     16parent = children[0].get_parent() # gets the parent
     17
     18}}}
     19
     20Preordered trees are great if done correctly, this is not.
Back to Top