Django prefetch_related children of children
问题 I have a model Node that looks something like that: class Node(models.Model): parent = models.ForeignKey('self', related_name='children', on_delete=models.CASCADE) A Node can have several children, and each of these children can have its own children. If I do: def show_child(node): for child in node.children.all(): show_child(child) root_node = Node.objects.prefetch_related('children').get(pk=my_node_id) # hit database twice, as expected print("Now testing queries") root_node.children.all() #