Esempio n. 1
0
 def alter_field(self, app_label, model_name, name, field,
                 preserve_default):
     if not preserve_default:
         field = field.clone()
         field.default = NOT_PROVIDED
     else:
         field = field
     model_key = app_label, model_name
     fields = self.models[model_key].fields
     if self._relations is not None:
         old_field = fields.pop(name)
         if old_field.is_relation:
             self.resolve_model_field_relations(model_key, name, old_field)
         fields[name] = field
         if field.is_relation:
             self.resolve_model_field_relations(model_key, name, field)
     else:
         fields[name] = field
     # TODO: investigate if old relational fields must be reloaded or if
     # it's sufficient if the new field is (#27737).
     # 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 field_is_referenced(self, model_key, (name, field)))
     self.reload_model(*model_key, delay=delay)
Esempio n. 2
0
 def alter_field(self, app_label, model_name, name, field,
                 preserve_default):
     if not preserve_default:
         field = field.clone()
         field.default = NOT_PROVIDED
     else:
         field = field
     model_state = self.models[app_label, model_name]
     model_state.fields[name] = field
     # TODO: investigate if old relational fields must be reloaded or if
     # it's sufficient if the new field is (#27737).
     # 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 field_is_referenced(self, (app_label, model_name),
                                          (name, field)))
     self.reload_model(app_label, model_name, delay=delay)
Esempio n. 3
0
 def state_forwards(self, app_label, state):
     if not self.preserve_default:
         field = self.field.clone()
         field.default = NOT_PROVIDED
     else:
         field = self.field
     model_state = state.models[app_label, self.model_name_lower]
     model_state.fields[self.name] = field
     # TODO: investigate if old relational fields must be reloaded or if it's
     # sufficient if the new field is (#27737).
     # 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 field_is_referenced(
         state,
         (app_label, self.model_name_lower),
         (self.name, field),
     ))
     state.reload_model(app_label, self.model_name_lower, delay=delay)