I have the following SQLAlchemy class representing an adjacency list:

class Node(db.Model):
    __tablename__ = 'meds'
    id = Column(Integer, primary_key=True)
    type = Column(String(64))
    name = Column(String(64))
    parent_id = Column(Integer, ForeignKey('node.id'))
    children = relationship("Node")

I need to create a dictionary to represent a tree of arbitrary depth that 
would look like:


{
"children": [
    {
      "children": [
        {
          "id": 4, 
          "name": "Child1", 
          "parent_id": 3, 
          "type": "Parent 2"
          "children": [
            {
              "id": 6, 
              "name": "Child3", 
              "parent_id": 3, 
              "type": "Parent 3",
              "children": [...]
            }, 
            {
              "id": 7, 
              "name": "Child4", 
              "parent_id": 3, 
              "type": "Leaf"
           }
          ]
        }, 
        {
          "id": 5, 
          "name": "Child2", 
          "parent_id": 3, 
          "type": "Leaf"
        }
      ], 
      "id": 3, 
      "name": "CardioTest", 
      "parent_id": null, 
      "type": "Parent"
    }
  ]
}


Can this dictionary be built non-recursively? I am not sure how to manually 
do this otherwise. 

Thanks in advance!

Greg--

-- 
You received this message because you are subscribed to the Google Groups 
"sqlalchemy" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to sqlalchemy+unsubscr...@googlegroups.com.
To post to this group, send email to sqlalchemy@googlegroups.com.
Visit this group at https://groups.google.com/group/sqlalchemy.
For more options, visit https://groups.google.com/d/optout.

Reply via email to