[Fixed]-What are the advantages of django-treebeard over django-mptt?

16👍

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.

5👍

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).

2👍

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

👤Magere

Leave a comment