I'm attempting to use Django to produce a recursive relationship, which provides customers a folder-like hierarchical structure to place assets.

An amount be the easiest method to accomplish this?

I understand I possibly could use treebeard or mptt to produce a nested set however i read that creating changes towards the tree structure (something that might be happening a great deal within this situation) can be very a rigorous operation as many fields need to be up-to-date.

However, I possibly could folder model having a ForeignKey to self but how do you manage the very best level folders without any foreign key value? Will Django complain basically just set this value to become NULL?

Any advice appreciated.


Treebeard really supports three different tree implementations, just choose the one which will suite your requirements.

  • Adjacency List (fast creates at the expense of slow reads)
  • Materialized Path (most likely the quickest method of dealing with trees in SQL)
  • Nested Sets (extremely powerful reads at the expense of high maintenance on write/remove procedures)

Paperwork are here: https://tabo.pe/projects/django-treebeard/docs/tip/