MCPcopy
hub / github.com/django/django / get_distinct

Method get_distinct

django/db/models/sql/compiler.py:1034–1058  ·  view source on GitHub ↗

Return a quoted list of fields to use in DISTINCT ON part of the query. This method can alter the tables in the query, and thus it must be called before get_from_clause().

(self)

Source from the content-addressed store, hash-verified

1032 return result
1033
1034 def get_distinct(self):
1035 """
1036 Return a quoted list of fields to use in DISTINCT ON part of the query.
1037
1038 This method can alter the tables in the query, and thus it must be
1039 called before get_from_clause().
1040 """
1041 result = []
1042 params = []
1043 opts = self.query.get_meta()
1044
1045 for name in self.query.distinct_fields:
1046 parts = name.split(LOOKUP_SEP)
1047 _, targets, alias, joins, path, _, transform_function = self._setup_joins(
1048 parts, opts, None
1049 )
1050 targets, alias, _ = self.query.trim_joins(targets, joins, path)
1051 for target in targets:
1052 if name in self.query.annotation_select:
1053 result.append(self.connection.ops.quote_name(name))
1054 else:
1055 r, p = self.compile(transform_function(target, alias))
1056 result.append(r)
1057 params.append(p)
1058 return result, params
1059
1060 def find_ordering_name(
1061 self, name, opts, alias=None, default_order="ASC", already_seen=None

Callers 1

as_sqlMethod · 0.95

Calls 7

_setup_joinsMethod · 0.95
compileMethod · 0.95
trim_joinsMethod · 0.80
get_metaMethod · 0.45
splitMethod · 0.45
appendMethod · 0.45
quote_nameMethod · 0.45

Tested by

no test coverage detected