'Makes a Model class out of the given app name, model name and pickled data.'

def make_model(self, app, name, data):

    if ('_ormbases' in data['Meta']):
        for key in data['Meta']['_ormbases']:
            key = key.lower()
            if (key not in self.models):
                raise ORMBaseNotIncluded(('Cannot    find    ORM    base    %s' % key))
            elif isinstance(self.models[key], string_types):
                raise UnfreezeMeLater()
        bases = [self.models[key.lower()] for key in data['Meta']['_ormbases']]
    elif ('_bases' in data['Meta']):
        bases = map(ask_for_it_by_name, data['Meta']['_bases'])
    else:
        bases = [models.Model]
    meta = self.make_meta(app, name, data['Meta'], data.get('_stub', False))
    failed_fields = {}
    fields = {}
    stub = False
    for (fname, params) in data.items():
        if (fname == '_stub'):
            stub = bool(params)
            continue
        elif (fname == 'Meta'):
            continue
        elif (not params):
            raise ValueError(("Field    '%s'    on    model    '%s.%s'    has    no    definition." % (fname, app, name)))
        elif isinstance(params, string_types):
            code = params
            extra_imports = {}
        else:
            if (len(params) == 1):
                params = (params[0], [], {})
            if (len(params) == 3):
                code = ('SouthFieldClass(%s)' % ',    '.join((params[1] + [('%s=%s' % (n, v)) for (n, v) in params[2].items()])))
                extra_imports = {'SouthFieldClass': params[0]}
            else:
                raise ValueError(("Field    '%s'    on    model    '%s.%s'    has    a    weird    definition    length    (should    be    1    or    3    items)." % (fname, app, name)))
        try:
            field = self.eval_in_context(code, app, extra_imports)
        except (NameError, AttributeError, AssertionError, KeyError):
            failed_fields[fname] = (code, extra_imports)
        else:
            fields[fname] = field
    more_kwds = {}
    try:
        app_module = models.get_app(app)
        more_kwds['__module__'] = app_module.__name__
    except ImproperlyConfigured:
        more_kwds['__module__'] = '_south_mock'
    more_kwds['Meta'] = meta
    fields.update(more_kwds)
    model = type(str(name), tuple(bases), fields)
    if stub:
        model.objects = WhinyManager()
        model.__init__ = whiny_method
    else:
        model.objects = NoDryRunManager(model.objects)
    if failed_fields:
        model._failed_fields = failed_fields
    return model
