def get_autocomplete_location_query(qs, q):
    """Return qs if ``istartswith`` filter exists, else fallback to ``icontains``."""
    startswith_qs = qs.filter(name__istartswith=q)
    if startswith_qs.exists():
        return startswith_qs
    return qs.filter(name__icontains=q)