import importlib


def import_model(type_module, type_name):
    """
    :param str type_module:
    :param str type_name:
    :return: Model type
    :rtype: type
    :raise ImportError: When the model cannot be found.
    """
    try:
        mod = importlib.import_module(type_module)
    except ImportError as e:
        raise ImportError("Import {}.{} failed; {}".format(type_module, type_name, e))

    try:
        type_ = getattr(mod, type_name)
    except AttributeError:
        raise ImportError("Import {0}.{1} failed; No class named {1}".format(type_module, type_name))

    return type_