diff options
Diffstat (limited to 'django/db/models/sql')
| -rw-r--r-- | django/db/models/sql/query.py | 35 |
1 files changed, 35 insertions, 0 deletions
diff --git a/django/db/models/sql/query.py b/django/db/models/sql/query.py index 426087f8af..d94a3abda5 100644 --- a/django/db/models/sql/query.py +++ b/django/db/models/sql/query.py @@ -1847,6 +1847,41 @@ class Query(object): self.extra_select_mask = set(names) self._extra_select_cache = None + def set_values(self, fields): + self.select_related = False + self.clear_deferred_loading() + self.clear_select_fields() + + if self.group_by is True: + self.add_fields((f.attname for f in self.model._meta.concrete_fields), False) + self.set_group_by() + self.clear_select_fields() + + if fields: + field_names = [] + extra_names = [] + annotation_names = [] + if not self._extra and not self._annotations: + # Shortcut - if there are no extra or annotations, then + # the values() clause must be just field names. + field_names = list(fields) + else: + self.default_cols = False + for f in fields: + if f in self.extra_select: + extra_names.append(f) + elif f in self.annotation_select: + annotation_names.append(f) + else: + field_names.append(f) + self.set_extra_mask(extra_names) + self.set_annotation_mask(annotation_names) + else: + field_names = [f.attname for f in self.model._meta.concrete_fields] + + self.values_select = field_names + self.add_fields(field_names, True) + @property def annotation_select(self): """The OrderedDict of aggregate columns that are not masked, and should |
