'Returns the models in the order that they should be dealt with (i.e.
models with no dependencies first).'

def ordered_keys(self):

    dealt_with = SortedDict()
    models = self.data.keys()
    while (len(dealt_with) < len(models)):
        found = False
        for model in models:
            if (model in dealt_with):
                continue
            children = self.children.setdefault(model, [])
            if (len([c for c in children if (c not in dealt_with)]) == 0):
                dealt_with[model] = None
                found = True
        if (not found):
            raise CyclicDependency('There    is    a    cyclic    dependency    of    items    to    be    processed.')
    return dealt_with.keys()
