@set_database
def get_topic_nodes_with_children(parent=None, **kwargs):
 if parent:
  Parent = Item.alias()
  Child = Item.alias()
  if (parent == 'root'):
   selector = Parent.parent.is_null()
  else:
   selector = (Parent.id == parent)
  child_values = [item for item in Item.select(Child).join(Child, on=(Child.parent == Item.pk)).join(Parent, on=(Item.parent == Parent.pk)).where(selector).dicts()]
  parent_values = [item for item in Item.select(Item).join(Parent, on=(Item.parent == Parent.pk)).where(selector).dicts()]
  topics = []
  for topic in parent_values:
   output = {}
   output.update(topic)
   output['children'] = [child['id'] for child in child_values if (child['parent'] == topic['pk'])]
   topics.append(output)
  return topics

@ set_database def get_topic_nodes_with_children ( parent = None , ** kwargs ) : if parent : Parent = Item . alias ( ) Child = Item . alias ( ) if ( parent == 'root' ) : selector = Parent . parent . is_null ( ) else : selector = ( Parent . id == parent ) child_values = [ item for item in Item . select ( Child ) . join ( Child , on = ( Child . parent == Item . pk ) ) . join ( Parent , on = ( Item . parent == Parent . pk ) ) . where ( selector ) . dicts ( ) ] parent_values = [ item for item in Item . select ( Item ) . join ( Parent , on = ( Item . parent == Parent . pk ) ) . where ( selector ) . dicts ( ) ] topics = [ ] for topic in parent_values : output = { } output . update ( topic ) output [ 'children' ] = [ child [ 'id' ] for child in child_values if ( child [ 'parent' ] == topic [ 'pk' ] ) ] topics . append ( output ) return topics
convenience function for returning a set of topic nodes with children listed as ids .