I think it would be better to store each node's level as a field in the model, so that we can generate the json representation of the tree easier and more efficiently. In large trees, it's not feasible to get level of each node. That's too many db calls.