1👍
OK, I got it right, query for ancestors should say:
ancestors = Part.objects.filter(closures_a__descendant_id__exact=self.id)
instead of:
ancestors = Part.objects.filter(closures_d__descendant__id__exact=self.id)
Query returns correct results, but displayed SQL still looks wrong (no JOIN),
I have no idea why, I got generated query using this code (path function from class Part from question):
def path(self):
ancestors = Part.objects.filter(closures_a__descendant_id__exact=self.id)
from django.db import connection
print(connection.queries)
return "{}".format(reduce(lambda a, b: a+" > "+b, map(lambda x: x.name, ancestors), ""))
Source:stackexchange.com