Django MPTT 0.2 Released
The second public release of Django MPTT is now available for download.
Backwards-incompatible changes:
mptt.registerreplacesmptt.models.treeifyfor registering models with the mptt application.move_nodeis now the only "public" method for moving nodes inTreeManager- it will figure out what do do based on its arguments. Other, peviously public, methods have been renamed with a preceding underscore to indicate the internal nature of their intended use.
New and improved features:
-
insert_at(target, position, commit)is_child_node()is_root_node()is_leaf_node()get_children()get_next_sibling()get_previous_sibling()get_root()
New
TreeManagermethods:insert_node(node, target, position)- insert a new node at any position in the tree, no need to save and then move any more.root_node(tree_id)root_nodes()
- Tree options are now held in the
Options(a.k.a._meta) for each registered model. - Added an
order_insertion_byoption when registering a model. If a field name is provided, new nodes will automatically be inserted so they're ordered based on the given field at each level in the tree. This ordering is also maintained when automatic reparenting is performed (i.e. when you change a node's parent, then save it). - Nodes can now be moved to be siblings of root nodes - this is a special case due to Django MPTT's use of a tree id field, and used to be an invalid move.
TreeManager.move_nodenow performs transaction management in the same manner as modelsave()anddelete()methods.- Added a
drilldown_tree_for_nodetemplate tag. - Added a
tree_pathtemplate filter. - The
tree_infotemplate filter now accepts an optional argument which can be used to specify that ancestor information be made available for each node in the tree. - Added a custom
newformsForm,MoveNodeForm, which takes care of moving a given node to any of a given selection of valid target nodes in the tree.
Browse the version 0.2 HTML documentation online for more details.
Posted by jonny on January 16, 2008

Comments
Rock Howard January 16, 2008 at 2:13 a.m.
I am using this release in a simple ToDo List style application that I just whipped together. I have tried about 1/2 the functions and tags so far and everything seems to be in order. However the documentation is slim and the section covering the template tags is confusing. The overall design seems pretty sharp though and installation is drop dead simple. I think this app has good potential. Recommended.
Simeon January 16, 2008 at 3:39 a.m.
I haven't gotten a chance to pump mptt on my blog yet, but I just wanted to say thanks. I'm using mptt in a menu app and previously had a simple "parent" field and recursive application of a template in a template tag. mptt has been a great step up and I really think with newforms-admin making tree style admin apps possible mptt will be a great candidate for django.contrib.
Lars January 16, 2008 at 10:01 a.m.
I'm also using mptt for a menu app, and have found it really neat and simple to get running. Managing hierarchical data structures in relational databases have always been cumbersome, but this django app really makes it a lot simpler. I agree the documentation needs some work, but it's quite good for a 0.2 release so I'm sure that will be fixed over time.
Oumer February 3, 2008 at 6:26 p.m.
Hello!
Thanks for the app, it sounds very promising! I was trying to use it but I come across this problem...any idea what is going on? it seems mptt is trying to find some field that doesn't exist in the model...I have posted my code as well as the error at
http://dpaste.com/33601/
Thanks in advance!
Oumer
class Genre(models.Model):
name = models.CharField(max_length=50, null=False, blank=False, unique=True)
description = models.TextField(max_length=250, null=True, blank=True, unique=False)
parent = models.ForeignKey('self', null=True, blank=True, related_name='children')
def __unicode__(self):
return self.name
class Meta:
verbose_name_plural = 'Categories'
class Admin:
pass
mptt.register(Genre,order_insertion_by="name")
I have syncdb..and the table structure looks ok, i.e. the additional fields are added as promised by mptt...so the table structure is (from sqlite3 dump table command)
BEGIN TRANSACTION;
CREATE TABLE "offers_genre" (
"id" integer NOT NULL PRIMARY KEY,
"name" varchar(50) NOT NULL UNIQUE,
"description" text NULL,
"parent_id" integer NULL,
"lft" integer unsigned NOT NULL,
"rght" integer unsigned NOT NULL,
"tree_id" integer unsigned NOT NULL,
"level" integer unsigned NOT NULL
);
CREATE INDEX "offers_genre_parent_id" ON "offers_genre" ("parent_id");
CREATE INDEX "offers_genre_lft" ON "offers_genre" ("lft");
CREATE INDEX "offers_genre_rght" ON "offers_genre" ("rght");
CREATE INDEX "offers_genre_tree_id" ON "offers_genre" ("tree_id");
CREATE INDEX "offers_genre_level" ON "offers_genre" ("level");
COMMIT;
#what I am trying to do:
on a python shell trying to put some data into the table...
g1=Genre(name="Rock", description="Music with an attitude");and save it
g1.save()
but the save is giving me this error...
Comments are currently disabled