Django: Best way for simple hierarchy?

I have this model:

class Category(models.Model):
    name = models.CharField()
    description = models.CharField(blank=True)
    parent = models.ForeignKey('self', blank=True, null=True)

I want Django to sort the categories with respect to their hierarchy, for example:

  • Parent 1
    • Child 1
  • Parent 2
    • Child 1

I did some research and found 2 apps, treebeard.al_tree and Django MPTT, both are powerful which may lead to lower performance or harder to maintain.

I will display the categories in website's sidebar and inside admin pages (includes ForeignKey in posts model), there will be very low additions/modifications/deletions to categories, mostly reading only which should have no big affect on performance.

Is there any other app which offers this and simpler than those above? Can I achieve this using Django without additional apps, using managers or something else?


I do not see any disadvantes using an app like django-mptt. In fact the methods provided by it are optimized to give you a maximum in performance when doing queries with hierarchical structures. No reason for me to worry about maintainability and/or performance and it is quite easy to use!

MPTT or treebeard may lead to lower performance? Nonsense. The whole point of these apps is that they provide highly optimised algorithms that massively increase performance. MPTT allows you to grab whole trees or sub-sections of them with a single database operation, which would otherwise need many separate calls.

Need Your Help

C / C++ compiler warnings: do you clean up all your code to remove them or leave them in?

c++ c compiler-construction warnings

I've worked on many projects where I've been given code by others to update. More often than not I compile it and get about 1,000+ compiler warnings. When I see compiler warnings they make me feel ...

Panel which stacks child elements horizontally, fitting them into the available size

c# wpf layout panel

I'm looking for some layout panel for WPF which "stacks" its children horizontally, but fits them all into the panel, i.e. not like StackPanel which just keeps on adding them with their full width....