'Return True if \'distinct()\' should be used to query the given lookups.'

def must_call_distinct(self, queryset, search_fields):

    for search_field in search_fields:
        opts = queryset.model._meta
        if (search_field[0] in self.lookup_prefixes):
            search_field = search_field[1:]
        parts = search_field.split(LOOKUP_SEP)
        for part in parts:
            field = opts.get_field(part)
            if hasattr(field, u'get_path_info'):
                path_info = field.get_path_info()
                opts = path_info[(-1)].to_opts
                if any((path.m2m for path in path_info)):
                    return True
    return False
