diff options
| author | Adam Chainz <me@adamj.eu> | 2016-12-23 15:12:48 +0000 |
|---|---|---|
| committer | Tim Graham <timograham@gmail.com> | 2016-12-23 10:12:48 -0500 |
| commit | 8d94d575f821b16a25bfd9fcf739f2ee2febe2be (patch) | |
| tree | 5f79615c3284a177c8bfc209e9846823f2ff5218 | |
| parent | 6ebf8f9057893b802fa85599573886081f32edc9 (diff) | |
Used @cached_property in RawQuerySet.
| -rw-r--r-- | django/db/models/query.py | 40 |
1 files changed, 18 insertions, 22 deletions
diff --git a/django/db/models/query.py b/django/db/models/query.py index 6a0b1ca0ac..7db076cc58 100644 --- a/django/db/models/query.py +++ b/django/db/models/query.py @@ -1241,38 +1241,34 @@ class RawQuerySet(object): using=alias, ) - @property + @cached_property def columns(self): """ A list of model field names in the order they'll appear in the query results. """ - if not hasattr(self, '_columns'): - self._columns = self.query.get_columns() - - # Adjust any column names which don't match field names - for (query_name, model_name) in self.translations.items(): - try: - index = self._columns.index(query_name) - self._columns[index] = model_name - except ValueError: - # Ignore translations for non-existent column names - pass - - return self._columns + columns = self.query.get_columns() + # Adjust any column names which don't match field names + for (query_name, model_name) in self.translations.items(): + try: + index = columns.index(query_name) + columns[index] = model_name + except ValueError: + # Ignore translations for non-existent column names + pass + return columns - @property + @cached_property def model_fields(self): """ A dict mapping column names to model field names. """ - if not hasattr(self, '_model_fields'): - converter = connections[self.db].introspection.table_name_converter - self._model_fields = {} - for field in self.model._meta.fields: - name, column = field.get_attname_column() - self._model_fields[converter(column)] = field - return self._model_fields + converter = connections[self.db].introspection.table_name_converter + model_fields = {} + for field in self.model._meta.fields: + name, column = field.get_attname_column() + model_fields[converter(column)] = field + return model_fields class Prefetch(object): |
