S
S
Sergey Nizhny Novgorod2017-06-15 02:33:38
Django
Sergey Nizhny Novgorod, 2017-06-15 02:33:38

How to make a directory with a large level of nesting of categories?

Hello everyone
. Such a question, but how to make a directory in Django with nesting of subcategories by 4-5 levels? I usually made a field with a category selection, but how to nest categories?

Answer the question

In order to leave comments, you need to log in

3 answer(s)
E
Eugene, 2017-06-15
@Terras

You can use django-treebeard or django-mptt
dajngopackages to help you

B
Bulat Minnemullin, 2017-06-15
@minbulat

You can add a parent field to the category, which will refer to the category class itself:

class Category(models.Model):
    ...
    parent = models.ForeignKey('self', blank=True, null=True, verbose_name="Родитель", related_name='children')

E
epolyak, 2017-06-26
@epolyak

For such purposes, I would start a mongo (MongoDB) or something similar and store the tree there, without any joins and other things, you take the tree with one request and all the required information is already in the RDBMS

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question