def re_map_foreign_keys(data, table, field_name, related_table, verbose=False):
 lookup_table = id_maps[related_table]
 for item in data[table]:
  old_id = item[field_name]
  if (old_id in lookup_table):
   new_id = lookup_table[old_id]
   if verbose:
    logging.info(('Remapping %s%s from %s to %s' % (table, (field_name + '_id'), old_id, new_id)))
  else:
   new_id = old_id
  item[(field_name + '_id')] = new_id
  del item[field_name]

def re_map_foreign_keys ( data , table , field_name , related_table , verbose = False ) : lookup_table = id_maps [ related_table ] for item in data [ table ] : old_id = item [ field_name ] if ( old_id in lookup_table ) : new_id = lookup_table [ old_id ] if verbose : logging . info ( ( 'Remapping %s%s from %s to %s' % ( table , ( field_name + '_id' ) , old_id , new_id ) ) ) else : new_id = old_id item [ ( field_name + '_id' ) ] = new_id del item [ field_name ]
we occasionally need to assign new ids to rows during the import/export process .