def add_syncing_models(models, dependency_check=False):
 get_foreign_key_classes = (lambda m: set([field.rel.to for field in m._meta.fields if isinstance(field, ForeignKey)]))
 for model in models:
  if (model in _syncing_models):
   logging.debug(('We are already syncing model %s; likely from different ways of importing the same models file.' % unicode(model)))
   continue
  foreign_key_classes = get_foreign_key_classes(model)
  class_indices = [_syncing_models.index(cls) for cls in foreign_key_classes if (cls in _syncing_models)]
  insert_after_idx = (1 + (max(class_indices) if class_indices else (-1)))
  if (dependency_check and [True for synmod in _syncing_models[0:(insert_after_idx - 1)] if (model in get_foreign_key_classes(synmod))]):
   raise Exception('Dependency loop detected in syncing models; cannot proceed.')
  _syncing_models.insert((insert_after_idx + 1), model)

def add_syncing_models ( models , dependency_check = False ) : get_foreign_key_classes = ( lambda m : set ( [ field . rel . to for field in m . _meta . fields if isinstance ( field , ForeignKey ) ] ) ) for model in models : if ( model in _syncing_models ) : logging . debug ( ( 'We are already syncing model %s; likely from different ways of importing the same models file.' % unicode ( model ) ) ) continue foreign_key_classes = get_foreign_key_classes ( model ) class_indices = [ _syncing_models . index ( cls ) for cls in foreign_key_classes if ( cls in _syncing_models ) ] insert_after_idx = ( 1 + ( max ( class_indices ) if class_indices else ( - 1 ) ) ) if ( dependency_check and [ True for synmod in _syncing_models [ 0 : ( insert_after_idx - 1 ) ] if ( model in get_foreign_key_classes ( synmod ) ) ] ) : raise Exception ( 'Dependency loop detected in syncing models; cannot proceed.' ) _syncing_models . insert ( ( insert_after_idx + 1 ) , model )
when sync is run .