Aidas Bendoraitis
Aidas Bendoraitis

Reputation: 4003

What are the advantages of django-treebeard over django-mptt?

There are two well known Django packages for creating tree structures: django-treebeard and django-mptt. Recently Django CMS started using django-treebeard instead of django-mptt. Wagtail CMS is also using django-treebeard.

What makes django-treebeard a more preferable choice than django-mptt?

Upvotes: 16

Views: 5824

Answers (3)

Jacob Fredericksen
Jacob Fredericksen

Reputation: 180

Most importantly, django-mptt is explicitly unmaintained:

https://github.com/django-mptt/django-mptt#this-project-is-currently-unmaintained

So, at this point, using django-mptt carries the significant risk that you won't be able to use current versions of other packages (depended on by django-mptt) and will eventually run into problems that will require you to switch to a different package like django-treebeard.

side note for Postgres users

Incidentally, for Postgres users, there is another interesting alternative to mptt: ltree (https://www.postgresql.org/docs/current/ltree.html).

Currently (at the time I'm writing this), there's no maintained package for integrating ltree with Django. However, django-treebeard has an open issue for adding ltree support: https://github.com/django-treebeard/django-treebeard/issues/170

In the meantime, it's easy enough to implement without a package. Here's a demo I found: https://github.com/peopledoc/django-ltree-demo. I can confirm that this demo still works well (even though the code is a few years old).

Upvotes: 5

Magere
Magere

Reputation: 99

You get more options with treebeard, which allows several tree implementations with the same API.

TREEBEARD: Adjacency List, Materialized Path, & Nested Sets

MPTT: NESTED sets

Also, MPTT may be slower in big-tree-operations involving more than 1000 nodes, so I'd say project size should factor into your considerations.

For more information checkout this DjangoCon Talk by one of the TREEBEARD maintainers Jacob Rief. The talk is on "Representing Hierarchies in Relational Databases" Check out his GitHub

Upvotes: 2

Tom Carrick
Tom Carrick

Reputation: 6616

The main difference is choice of SQL tree implementation.

django-mptt uses nested sets, which is fast for reads, slow for writes.

Treebeard offers nested sets, as well as adjacency lists (fast writes, slow reads) and materialized path (fast reads, fastish writes).

There are also other differences. django-mptt has a nicer API and better docs.

Upvotes: 16

Related Questions