Kaydet (Commit) 8d94d575 authored tarafından Adam Chainz's avatar Adam Chainz Kaydeden (comit) Tim Graham

Used @cached_property in RawQuerySet.

üst 6ebf8f90
...@@ -1241,38 +1241,34 @@ class RawQuerySet(object): ...@@ -1241,38 +1241,34 @@ class RawQuerySet(object):
using=alias, using=alias,
) )
@property @cached_property
def columns(self): def columns(self):
""" """
A list of model field names in the order they'll appear in the A list of model field names in the order they'll appear in the
query results. query results.
""" """
if not hasattr(self, '_columns'): columns = self.query.get_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():
# Adjust any column names which don't match field names try:
for (query_name, model_name) in self.translations.items(): index = columns.index(query_name)
try: columns[index] = model_name
index = self._columns.index(query_name) except ValueError:
self._columns[index] = model_name # Ignore translations for non-existent column names
except ValueError: pass
# Ignore translations for non-existent column names return columns
pass
return self._columns
@property @cached_property
def model_fields(self): def model_fields(self):
""" """
A dict mapping column names to model field names. A dict mapping column names to model field names.
""" """
if not hasattr(self, '_model_fields'): converter = connections[self.db].introspection.table_name_converter
converter = connections[self.db].introspection.table_name_converter model_fields = {}
self._model_fields = {} for field in self.model._meta.fields:
for field in self.model._meta.fields: name, column = field.get_attname_column()
name, column = field.get_attname_column() model_fields[converter(column)] = field
self._model_fields[converter(column)] = field return model_fields
return self._model_fields
class Prefetch(object): class Prefetch(object):
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment