Refs #29000 -- Restored delayed model rendering of RenameField.
Non-delayed rendering is unnecessary and wasteful now that state models
relationship consistency on delayed reload is ensured.
This partly reverts commit fcc4e251db
.
This commit is contained in:
parent
1d16c5d562
commit
ad811335bd
|
@ -304,11 +304,16 @@ class RenameField(FieldOperation):
|
||||||
# Rename the field
|
# Rename the field
|
||||||
fields = model_state.fields
|
fields = model_state.fields
|
||||||
found = False
|
found = False
|
||||||
delay = True
|
|
||||||
for index, (name, field) in enumerate(fields):
|
for index, (name, field) in enumerate(fields):
|
||||||
if not found and name == self.old_name:
|
if not found and name == self.old_name:
|
||||||
fields[index] = (self.new_name, field)
|
fields[index] = (self.new_name, field)
|
||||||
found = True
|
found = True
|
||||||
|
# Delay rendering of relationships if it's not a relational
|
||||||
|
# field and not referenced by a foreign key.
|
||||||
|
delay = (
|
||||||
|
not field.is_relation and
|
||||||
|
not is_referenced_by_foreign_key(state, self.model_name_lower, field, self.name)
|
||||||
|
)
|
||||||
# Fix from_fields to refer to the new field.
|
# Fix from_fields to refer to the new field.
|
||||||
from_fields = getattr(field, 'from_fields', None)
|
from_fields = getattr(field, 'from_fields', None)
|
||||||
if from_fields:
|
if from_fields:
|
||||||
|
@ -316,12 +321,6 @@ class RenameField(FieldOperation):
|
||||||
self.new_name if from_field_name == self.old_name else from_field_name
|
self.new_name if from_field_name == self.old_name else from_field_name
|
||||||
for from_field_name in from_fields
|
for from_field_name in from_fields
|
||||||
])
|
])
|
||||||
# Delay rendering of relationships if it's not a relational
|
|
||||||
# field and not referenced by a foreign key.
|
|
||||||
delay = delay and (
|
|
||||||
not field.is_relation and
|
|
||||||
not is_referenced_by_foreign_key(state, self.model_name_lower, field, self.name)
|
|
||||||
)
|
|
||||||
if not found:
|
if not found:
|
||||||
raise FieldDoesNotExist(
|
raise FieldDoesNotExist(
|
||||||
"%s.%s has no field named '%s'" % (app_label, self.model_name, self.old_name)
|
"%s.%s has no field named '%s'" % (app_label, self.model_name, self.old_name)
|
||||||
|
|
Loading…
Reference in New Issue