'Evaluates the given code in the context of the migration file.'

def eval_in_context(self, code, app, extra_imports={}):

    fake_locals = dict(((key, value) for (key, value) in inspect.getmodule(self.cls).__dict__.items() if (not (isinstance(value, type) and issubclass(value, models.Model) and hasattr(value, '_meta')))))
    fake_locals.update(dict([(name.split('.')[(-1)], model) for (name, model) in self.models.items()]))
    fake_locals.update(dict([(name.split('.')[(-1)], model) for (name, model) in self.models.items() if (name.split('.')[0] == app)]))
    fake_locals['orm'] = self
    fake_locals['_'] = (lambda x: x)
    fake_locals['datetime'] = datetime_utils
    for (name, value) in extra_imports.items():
        parts = value.split('.')
        try:
            obj = fake_locals[parts[0]]
            for part in parts[1:]:
                obj = getattr(obj, part)
        except (KeyError, AttributeError):
            pass
        else:
            fake_locals[name] = obj
            continue
        try:
            fake_locals[name] = ask_for_it_by_name(value)
        except ImportError:
            if (name == 'SouthFieldClass'):
                raise ValueError(("Cannot    import    the    required    field    '%s'" % value))
            else:
                print(("WARNING:    Cannot    import    '%s'" % value))
    fake_locals = ModelsLocals(fake_locals)
    return eval(code, globals(), fake_locals)
