def recurse_tree(self, attr):
        nodes = []
        node_type = getattr(self, attr)
        # N.B. We're expecting a Django M2M attribute here.
        for node in node_type.all():
            nodes.extend(node.recurse_tree(attr))

        nodes.extend(node_type.all())

        return nodes
Recurse M2M relationship tree, extending list as we go.
dataset/ETHPy150Open buildingenergy/buildingenergy-platform/seed/models.py/BuildingSnapshot.recurse_tree