Answer the question
In order to leave comments, you need to log in
Answer the question
In order to leave comments, you need to log in
category.category_set.all()
If you want prettier:
class Category(models.Model):
parent = models.ForeignKey('self', null=True, blank=True, related_name='children')
category.children.all()
For trees, you can use django-mptt, then you can pull out descendants with any nesting level in one request.
If you want all descendants, then you need a recursive query. Supported by most SQL, but I doubt that dzhanga can do something like that. It is necessary to write a query in pure sql. As an alternative, you can form a bunch of separate requests in jung, but this is a bad way. Pure sql or maybe someone wrote some library for this
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question