Skip to content

Commit

Permalink
converting get_new_fields to cahced properties
Browse files Browse the repository at this point in the history
  • Loading branch information
PirosB3 committed Jul 2, 2014
1 parent 354a7b7 commit bcba146
Show file tree
Hide file tree
Showing 6 changed files with 12 additions and 14 deletions.
2 changes: 1 addition & 1 deletion django/contrib/gis/db/models/sql/compiler.py
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ def get_default_columns(self, with_aliases=False, col_aliases=None,
seen = self.query.included_inherited_models.copy()
if start_alias:
seen[None] = start_alias
for field in opts.get_new_fields(types=DATA, opts=CONCRETE):
for field in opts.concrete_fields:
field_is_direct = isinstance(field, Field) or hasattr(field, 'is_gfk')
model = field.model if field_is_direct else field.parent_model._meta.concrete_model
if model == opts.model:
Expand Down
4 changes: 2 additions & 2 deletions django/db/models/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -681,7 +681,7 @@ def _save_table(self, raw=False, cls=None, force_insert=False,
for a single table.
"""
meta = cls._meta
non_pks = [f for f in meta.get_new_fields(types=DATA, opts=CONCRETE | LOCAL_ONLY) if not f.primary_key]
non_pks = [f for f in meta.local_concrete_fields if not f.primary_key]

if update_fields:
non_pks = [f for f in non_pks
Expand Down Expand Up @@ -713,7 +713,7 @@ def _save_table(self, raw=False, cls=None, force_insert=False,
**{field.name: getattr(self, field.attname)}).count()
self._order = order_value

fields = meta.get_new_fields(types=DATA, opts=CONCRETE | LOCAL_ONLY)
fields = meta.local_concrete_fields
if not pk_set:
fields = [f for f in fields if not isinstance(f, AutoField)]

Expand Down
2 changes: 1 addition & 1 deletion django/db/models/options.py
Original file line number Diff line number Diff line change
Expand Up @@ -471,7 +471,7 @@ def get_fields_with_model(self):

def get_concrete_fields_with_model(self):
return list(map(self._map_model, self.get_new_fields(types=DATA, opts=CONCRETE)))

def _fill_fields_cache(self):
cache = []
for parent in self.parents:
Expand Down
12 changes: 5 additions & 7 deletions django/db/models/query.py
Original file line number Diff line number Diff line change
Expand Up @@ -255,7 +255,7 @@ def iterator(self):
# If only/defer clauses have been specified,
# build the list of fields that are to be loaded.
if only_load:
for field in self.model._meta.get_new_fields(types=DATA, opts=CONCRETE):
for field in self.model._meta.concrete_fields:
field_is_direct = isinstance(field, Field) or hasattr(field, 'is_gfk')
model = field.model if field_is_direct else field.parent_model._meta.concrete_model
if model is self.model._meta.model:
Expand Down Expand Up @@ -423,7 +423,7 @@ def bulk_create(self, objs, batch_size=None):
return objs
self._for_write = True
connection = connections[self.db]
fields = self.model._meta.get_new_fields(types=DATA, opts=LOCAL_ONLY | CONCRETE)
fields = self.model._meta.local_concrete_fields
with transaction.atomic(using=self.db, savepoint=False):
if (connection.features.can_combine_inserts_with_and_without_auto_increment_pk
and self.model._meta.has_auto_field):
Expand Down Expand Up @@ -1358,7 +1358,7 @@ def get_klass_info(klass, max_depth=0, cur_depth=0, requested=None,
skip = set()
init_list = []
# Build the list of fields that *haven't* been requested
for field in klass._meta.get_new_fields(types=DATA, opts=CONCRETE):
for field in klass._meta.concrete_fields:
field_is_direct = isinstance(field, Field) or hasattr(field, 'is_gfk')
model = field.model if field_is_direct else field.parent_model._meta.concrete_model
if model == klass._meta.model:
Expand All @@ -1383,9 +1383,7 @@ def get_klass_info(klass, max_depth=0, cur_depth=0, requested=None,

field_count = len(klass._meta.concrete_fields)
# Check if we need to skip some parent fields.
local_concrete_fields = klass._meta.get_new_fields(types=DATA, opts=LOCAL_ONLY | CONCRETE)
concrete_fields = klass._meta.get_new_fields(types=DATA, opts=CONCRETE)
if from_parent and len(local_concrete_fields) != len(concrete_fields):
if from_parent and len(klass._meta.local_concrete_fields) != len(klass._meta.concrete_fields):
# Only load those fields which haven't been already loaded into
# 'from_parent'.
non_seen_models = [p for p in klass._meta.get_parent_list()
Expand Down Expand Up @@ -1504,7 +1502,7 @@ def get_cached_row(row, index_start, using, klass_info, offset=0,
for f, klass_info in reverse_related_fields:
# Transfer data from this object to childs.
parent_data = []
for rel_field in klass_info[0]._meta.get_new_fields(types=DATA):
for rel_field in klass_info[0]._meta.fields:
direct = isinstance(rel_field, Field) or hasattr(rel_field, 'is_gfk')
rel_model = rel_field.model if direct else rel_field.parent_model._meta.concrete_model
if rel_model == klass_info[0]._meta.model:
Expand Down
4 changes: 2 additions & 2 deletions django/db/models/sql/compiler.py
Original file line number Diff line number Diff line change
Expand Up @@ -299,7 +299,7 @@ def get_default_columns(self, with_aliases=False, col_aliases=None,
# be used by local fields.
seen_models = {None: start_alias}

for field in opts.get_new_fields(types=DATA, opts=CONCRETE):
for field in opts.concrete_fields:
field_is_direct = isinstance(field, Field) or hasattr(field, 'is_gfk')
model = field.model if field_is_direct else field.parent_model._meta.concrete_model
if model == opts.model:
Expand Down Expand Up @@ -639,7 +639,7 @@ def fill_related_selections(self, opts=None, root_alias=None, cur_depth=1,
else:
restricted = False

for f in opts.get_new_fields(types=DATA):
for f in opts.fields:
# TODO: deprecated
# The get_fields_with_model() returns None for fields that live
# in the field's local model. So, for those fields we want to use
Expand Down
2 changes: 1 addition & 1 deletion django/db/models/sql/query.py
Original file line number Diff line number Diff line change
Expand Up @@ -944,7 +944,7 @@ def setup_inherited_models(self):
root_alias = self.tables[0]
seen = {None: root_alias}

for field in opts.get_new_fields(types=DATA):
for field in opts.fields:
direct = isinstance(field, Field) or hasattr(field, 'is_gfk')
model = field.model if direct else field.parent_model._meta.concrete_model
if model == opts.model:
Expand Down

0 comments on commit bcba146

Please sign in to comment.