def METHOD_NAME(field, pattern):
    """
    Convert a glob-like search pattern to a Q object.
    Examples:
    >>> text_match("title", "foo")
    <Q: (AND: ('title__iexact', 'foo'))>
    >>> text_match("title", "foo*")
    <Q: (AND: ('title__istartswith', 'foo'))>
    >>> text_match("title", "*foo")
    <Q: (AND: ('title__iendswith', 'foo'))>
    >>> text_match("title", "*foo*")
    <Q: (AND: ('title__icontains', 'foo'))>
    Note that if there are multiple terms separated by '*', they can
    appear in any order:
    >>> text_match("title", "*foo*bar*")
    <Q: (AND: ('title__icontains', 'foo'), ('title__icontains', 'bar'))>
    """
    parts = pattern.split('*')
    if len(parts) == 1:
        return Q(**{field + '__iexact': pattern})
    constraints = []
    if parts[0]:
        constraints.append(Q(**{field + '__istartswith': parts[0]}))
    for p in parts[1:-1]:
        constraints.append(Q(**{field + '__icontains': p}))
    if parts[-1]:
        constraints.append(Q(**{field + '__iendswith': parts[-1]}))
    return functools.reduce(operator.and_, constraints)