Django: Best way to 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 according to their hierarchy, for example:

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

I did some research and found 2 applications, treebeard.al_tree and Django MPTT, which are powerful, which can lead to reduced performance or complexity in maintenance.

I will show categories on the sidebar of the website and on the administration pages (including ForeignKey in the message model), there will be very few additions / modifications / exceptions for categories, mainly read-only, which should not have a big impact on performance.

Are there any other applications that offer this and easier than the above? Can I achieve this using Django without additional applications, using managers or something else?

+3
3

, , django-mptt. , . / , !

+4

MPTT treebeard ? . , , . MPTT , .

+4

MPTT . , ( 30 ) . .

MPTT . .

Django MPTT ( v0.4) API . .

+2

Source: https://habr.com/ru/post/1778086/


All Articles