Answer the question
In order to leave comments, you need to log in
How to store category structure in Django model?
Let's say there is a category that has supercategories and subcategories. How to organize the database so that you can easily query the supercategories and subcategories of a particular category?
Did it like this:
category_nested = models.ManyToManyField('self', symmetrical=False)
ERRORS:
items.Category.category_nested: (fields.E304) Reverse accessor for 'Category.category_nested' clashes with reverse accessor for 'Category.category_parrent'.
HINT: Add or change a related_name argument to the definition for 'Category.category_nested' or 'Category.category_parrent'.
items.Category.category_parrent: (fields.E304) Reverse accessor for 'Category.category_parrent' clashes with reverse accessor for 'Category.category_nested'.
Answer the question
In order to leave comments, you need to log in
At the time, they also suffered. As a result, they began to store simply in the xlm text field with the structure. Pluses - very fast work with nesting by a simple xpath, minuses - there is no connection at the base level, but there are Sinhalese for this. Xml can be replaced with json.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question