import importlib


def import_from_str(import_string):
    """Import an object defined as import if it is an string.

    If `import_string` follows the format `path.to.module.object_name`,
    this method imports it; else it just return the object.
    """
    if isinstance(import_string, str):
        path, field_name = import_string.rsplit(".", 1)
        module = importlib.import_module(path)
        return getattr(module, field_name)
    else:
        return import_string