def find_missing_children(filters=None, dryrun=False):
 errors = []
 fixed = []
 query = Q('nodes.0', 'exists', True)
 if filters:
  query = (query & filters)
 with_children = models.Node.find(query)
 for parent in with_children:
  for child in parent.nodes:
   if (not child.node__parent):
    msg = u'Inconsistency: Child {} ({}) does not point to parent {} ({}). Attempting to fix.\n'.format(child.title, child._primary_key, parent.title, parent._primary_key)
    logger.info(msg)
    errors.append(child)
    if (dryrun is False):
     child.node__parent.append(parent)
     child.save()
     msg = u'Fixed inconsistency: Child {} ({}) does not point to parent {} ({}).\n'.format(child.title, child._primary_key, parent.title, parent._primary_key)
     logger.info(msg)
     fixed.append(child)
 return (errors, fixed)

def find_missing_children ( filters = None , dryrun = False ) : errors = [ ] fixed = [ ] query = Q ( 'nodes.0' , 'exists' , True ) if filters : query = ( query & filters ) with_children = models . Node . find ( query ) for parent in with_children : for child in parent . nodes : if ( not child . node__parent ) : msg = u'Inconsistency: Child {} ({}) does not point to parent {} ({}). Attempting to fix.\n' . format ( child . title , child . _primary_key , parent . title , parent . _primary_key ) logger . info ( msg ) errors . append ( child ) if ( dryrun is False ) : child . node__parent . append ( parent ) child . save ( ) msg = u'Fixed inconsistency: Child {} ({}) does not point to parent {} ({}).\n' . format ( child . title , child . _primary_key , parent . title , parent . _primary_key ) logger . info ( msg ) fixed . append ( child ) return ( errors , fixed )
find children that dont point to their parents .