(opts, lookup_path)
return False
Returns True if 'distinct()' should be used to query the given lookup path.

    This is adopted from the Django core. django-admin2 mandates that code
    doesn't depend on imports from django.contrib.admin.

    https://github.com/django/django/blob/1.9.6/django/contrib/admin/utils.py#L22
Returns True if 'distinct()' should be used to query the given lookup path.
Returns True if distinct () should be used to query the given lookup path .
def lookup_needs_distinct(opts, lookup_path):
    """
    Returns True if 'distinct()' should be used to query the given lookup path.

    This is adopted from the Django core. django-admin2 mandates that code
    doesn't depend on imports from django.contrib.admin.

    https://github.com/django/django/blob/1.9.6/django/contrib/admin/utils.py#L22
    """

    lookup_fields = lookup_path.split(LOOKUP_SEP)
    # Go through the fields (following all relations) and look for an m2m.
    for field_name in lookup_fields:
        if field_name == 'pk':
            field_name = opts.pk.name
        try:
            field = opts.get_field(field_name)
        except FieldDoesNotExist:
            # Ignore query lookups.
            continue
        else:
            if hasattr(field, 'get_path_info'):
                # This field is a relation; update opts to follow the relation.
                path_info = field.get_path_info()
                opts = path_info[-1].to_opts
                if any(path.m2m for path in path_info):
                    # This field is a m2m relation so distinct must be called.
                    return True
    return False
def lookup_needs_distinct ( opts , lookup_path ) : lookup_fields = lookup_path . split ( LOOKUP_SEP ) # Go through the fields (following all relations) and look for an m2m. for field_name in lookup_fields : if field_name == 'pk' : field_name = opts . pk . name try : field = opts . get_field ( field_name ) except FieldDoesNotExist : # Ignore query lookups. continue else : if hasattr ( field , 'get_path_info' ) : # This field is a relation; update opts to follow the relation. path_info = field . get_path_info ( ) opts = path_info [ - 1 ] . to_opts if any ( path . m2m for path in path_info ) : # This field is a m2m relation so distinct must be called. return True return False