Renamed ForeignObject.related_field to target_field
This commit is contained in:
parent
d43aa28f67
commit
f9c70bb3a1
|
@ -593,10 +593,10 @@ class Model(six.with_metaclass(ModelBase)):
|
||||||
continue
|
continue
|
||||||
setattr(self, field.attname, getattr(db_instance, field.attname))
|
setattr(self, field.attname, getattr(db_instance, field.attname))
|
||||||
# Throw away stale foreign key references.
|
# Throw away stale foreign key references.
|
||||||
if field.rel and field.get_cache_name() in self.__dict__:
|
if field.is_relation and field.get_cache_name() in self.__dict__:
|
||||||
rel_instance = getattr(self, field.get_cache_name())
|
rel_instance = getattr(self, field.get_cache_name())
|
||||||
local_val = getattr(db_instance, field.attname)
|
local_val = getattr(db_instance, field.attname)
|
||||||
related_val = None if rel_instance is None else getattr(rel_instance, field.related_field.attname)
|
related_val = None if rel_instance is None else getattr(rel_instance, field.target_field.attname)
|
||||||
if local_val != related_val:
|
if local_val != related_val:
|
||||||
del self.__dict__[field.get_cache_name()]
|
del self.__dict__[field.get_cache_name()]
|
||||||
self._state.db = db_instance._state.db
|
self._state.db = db_instance._state.db
|
||||||
|
|
|
@ -1082,7 +1082,7 @@ def create_many_related_manager(superclass, rel, reverse):
|
||||||
self.clear()
|
self.clear()
|
||||||
self.add(*objs)
|
self.add(*objs)
|
||||||
else:
|
else:
|
||||||
old_ids = set(self.using(db).values_list(self.target_field.related_field.attname, flat=True))
|
old_ids = set(self.using(db).values_list(self.target_field.target_field.attname, flat=True))
|
||||||
|
|
||||||
new_objs = []
|
new_objs = []
|
||||||
for obj in objs:
|
for obj in objs:
|
||||||
|
@ -1224,7 +1224,7 @@ def create_many_related_manager(superclass, rel, reverse):
|
||||||
target_model_qs = super(ManyRelatedManager, self).get_queryset()
|
target_model_qs = super(ManyRelatedManager, self).get_queryset()
|
||||||
if target_model_qs._has_filters():
|
if target_model_qs._has_filters():
|
||||||
old_vals = target_model_qs.using(db).filter(**{
|
old_vals = target_model_qs.using(db).filter(**{
|
||||||
'%s__in' % self.target_field.related_field.attname: old_ids})
|
'%s__in' % self.target_field.target_field.attname: old_ids})
|
||||||
else:
|
else:
|
||||||
old_vals = old_ids
|
old_vals = old_ids
|
||||||
filters = self._build_remove_filters(old_vals)
|
filters = self._build_remove_filters(old_vals)
|
||||||
|
@ -1941,7 +1941,7 @@ class ForeignKey(ForeignObject):
|
||||||
return name, path, args, kwargs
|
return name, path, args, kwargs
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def related_field(self):
|
def target_field(self):
|
||||||
return self.foreign_related_fields[0]
|
return self.foreign_related_fields[0]
|
||||||
|
|
||||||
def get_reverse_path_info(self):
|
def get_reverse_path_info(self):
|
||||||
|
@ -1987,19 +1987,19 @@ class ForeignKey(ForeignObject):
|
||||||
"Here we check if the default value is an object and return the to_field if so."
|
"Here we check if the default value is an object and return the to_field if so."
|
||||||
field_default = super(ForeignKey, self).get_default()
|
field_default = super(ForeignKey, self).get_default()
|
||||||
if isinstance(field_default, self.rel.to):
|
if isinstance(field_default, self.rel.to):
|
||||||
return getattr(field_default, self.related_field.attname)
|
return getattr(field_default, self.target_field.attname)
|
||||||
return field_default
|
return field_default
|
||||||
|
|
||||||
def get_db_prep_save(self, value, connection):
|
def get_db_prep_save(self, value, connection):
|
||||||
if value is None or (value == '' and
|
if value is None or (value == '' and
|
||||||
(not self.related_field.empty_strings_allowed or
|
(not self.target_field.empty_strings_allowed or
|
||||||
connection.features.interprets_empty_strings_as_nulls)):
|
connection.features.interprets_empty_strings_as_nulls)):
|
||||||
return None
|
return None
|
||||||
else:
|
else:
|
||||||
return self.related_field.get_db_prep_save(value, connection=connection)
|
return self.target_field.get_db_prep_save(value, connection=connection)
|
||||||
|
|
||||||
def get_db_prep_value(self, value, connection, prepared=False):
|
def get_db_prep_value(self, value, connection, prepared=False):
|
||||||
return self.related_field.get_db_prep_value(value, connection, prepared)
|
return self.target_field.get_db_prep_value(value, connection, prepared)
|
||||||
|
|
||||||
def value_to_string(self, obj):
|
def value_to_string(self, obj):
|
||||||
if not obj:
|
if not obj:
|
||||||
|
@ -2039,7 +2039,7 @@ class ForeignKey(ForeignObject):
|
||||||
# in which case the column type is simply that of an IntegerField.
|
# in which case the column type is simply that of an IntegerField.
|
||||||
# If the database needs similar types for key fields however, the only
|
# If the database needs similar types for key fields however, the only
|
||||||
# thing we can do is making AutoField an IntegerField.
|
# thing we can do is making AutoField an IntegerField.
|
||||||
rel_field = self.related_field
|
rel_field = self.target_field
|
||||||
if (isinstance(rel_field, AutoField) or
|
if (isinstance(rel_field, AutoField) or
|
||||||
(not connection.features.related_fields_match_type and
|
(not connection.features.related_fields_match_type and
|
||||||
isinstance(rel_field, (PositiveIntegerField,
|
isinstance(rel_field, (PositiveIntegerField,
|
||||||
|
@ -2062,7 +2062,7 @@ class ForeignKey(ForeignObject):
|
||||||
return converters
|
return converters
|
||||||
|
|
||||||
def get_col(self, alias, output_field=None):
|
def get_col(self, alias, output_field=None):
|
||||||
return super(ForeignKey, self).get_col(alias, output_field or self.related_field)
|
return super(ForeignKey, self).get_col(alias, output_field or self.target_field)
|
||||||
|
|
||||||
|
|
||||||
class OneToOneField(ForeignKey):
|
class OneToOneField(ForeignKey):
|
||||||
|
|
Loading…
Reference in New Issue