Get an instance by slug.

    :param model: a string, model name in rio.models
    :param slug: a string used to query by `slug`. This requires there is a
                 slug field in model definition.
    :return: None or a SQLAlchemy Model instance.

def get_instance_by_slug(model, slug, **kwargs):
    """Get an instance by slug.

    :param model: a string, model name in rio.models
    :param slug: a string used to query by `slug`. This requires there is a
                 slug field in model definition.
    :return: None or a SQLAlchemy Model instance.
    """
    try:
        model = get_model(model)
    except ImportError:
        return None

    query_params = dict(kwargs)
    query_params['slug'] = slug

    return model.query.filter_by(**query_params).first()