Django Treebeard


1. Nested Hierarchies

class Category(models.Model):
    parent = models.ForeignKey('self', blank=True, null=True, related_name='children')
    name = models.CharField(max_length=255)

2. Ancestor Queries

categories = Category.objects.get_descendants(root_category)
ancestors = Category.objects.get_ancestors(leaf_category)

3. Level Ordering

categories = Category.objects.order_by('mptt_level')

4. Tree Depth

max_depth = Category.objects.aggregate(Max('mptt_level'))['mptt_level__max']

5. Tree Walk

for node in Category.objects.walk():
    print(node.name)

6. Siblings

siblings = Category.objects.get_siblings(category)

7. Cousins

cousins = Category.objects.get_cousins(category)

8. Deleting Nodes

9. Moving Nodes

10. Custom Tree Models

11. Ancestor Query with Custom Tree

12. In-Memory Tree

13. Tree Distances

14. Tree Paths

15. Node Annotations

16. Tree Selection

17. Tree Serialization

18. Tree Deserialization

19. Lazy Tree

20. Custom Tree Attributes

21. Parentless Nodes

22. Tree Management

23. Tree Search

24. Tree Hierarchy Chart

25. Tree Web Interface

26. Nested Tree Structure

27. Tree Navigation

28. Tree Management Signals

29. Tree RichText

30. Tree Customization

31. Tree Permissions

32. Tree Templates

33. Tree Serialization Using UUID

34. Tree with Ordering

35. Tree Soft Delete

36. Tree with Self-Referencing Foreign Key