diff options
Diffstat (limited to 'django/db/models/fields/related_descriptors.py')
| -rw-r--r-- | django/db/models/fields/related_descriptors.py | 57 |
1 files changed, 30 insertions, 27 deletions
diff --git a/django/db/models/fields/related_descriptors.py b/django/db/models/fields/related_descriptors.py index 8da7aaef91..3e2150e0f6 100644 --- a/django/db/models/fields/related_descriptors.py +++ b/django/db/models/fields/related_descriptors.py @@ -309,17 +309,17 @@ class ForwardManyToOneDescriptor: ) remote_field = self.field.remote_field - # If we're setting the value of a OneToOneField to None, we need to clear - # out the cache on any old related object. Otherwise, deleting the - # previously-related object will also cause this object to be deleted, - # which is wrong. + # If we're setting the value of a OneToOneField to None, we need to + # clear out the cache on any old related object. Otherwise, deleting + # the previously-related object will also cause this object to be + # deleted, which is wrong. if value is None: - # Look up the previously-related object, which may still be available - # since we've not yet cleared out the related field. - # Use the cache directly, instead of the accessor; if we haven't + # Look up the previously-related object, which may still be + # available since we've not yet cleared out the related field. Use + # the cache directly, instead of the accessor; if we haven't # populated the cache, then we don't care - we're only accessing - # the object to invalidate the accessor cache, so there's no - # need to populate the cache just to expire it again. + # the object to invalidate the accessor cache, so there's no need + # to populate the cache just to expire it again. related = self.field.get_cached_value(instance, default=None) # If we've got an old related object, we need to clear out its @@ -357,7 +357,8 @@ class ForwardManyToOneDescriptor: class ForwardOneToOneDescriptor(ForwardManyToOneDescriptor): """ - Accessor to the related object on the forward side of a one-to-one relation. + Accessor to the related object on the forward side of a one-to-one + relation. In the example:: @@ -531,7 +532,8 @@ class ReverseOneToOneDescriptor: - ``self`` is the descriptor managing the ``restaurant`` attribute - ``instance`` is the ``place`` instance - - ``value`` is the ``restaurant`` instance on the right of the equal sign + - ``value`` is the ``restaurant`` instance on the right of the equal + sign Keep in mind that ``Restaurant`` holds the foreign key to ``Place``. """ @@ -586,12 +588,13 @@ class ReverseOneToOneDescriptor: for index, field in enumerate(self.related.field.local_related_fields): setattr(value, field.attname, related_pk[index]) - # Set the related instance cache used by __get__ to avoid an SQL query - # when accessing the attribute we just set. + # Set the related instance cache used by __get__ to avoid an SQL + # query when accessing the attribute we just set. self.related.set_cached_value(instance, value) - # Set the forward accessor cache on the related object to the current - # instance to avoid an extra SQL query if it's accessed later on. + # Set the forward accessor cache on the related object to the + # current instance to avoid an extra SQL query if it's accessed + # later on. self.related.field.set_cached_value(value, instance) def __reduce__(self): @@ -1076,8 +1079,8 @@ def create_forward_many_to_many_manager(superclass, rel, reverse): def _build_remove_filters(self, removed_vals): filters = Q.create([(self.source_field_name, self.related_val)]) - # No need to add a subquery condition if removed_vals is a QuerySet without - # filters. + # No need to add a subquery condition if removed_vals is a QuerySet + # without filters. removed_vals_filters = ( not isinstance(removed_vals, QuerySet) or removed_vals._has_filters() ) @@ -1145,8 +1148,8 @@ def create_forward_many_to_many_manager(superclass, rel, reverse): # M2M: need to annotate the query in order to get the primary model # that the secondary model was actually related to. We know that - # there will already be a join on the join table, so we can just add - # the select. + # there will already be a join on the join table, so we can just + # add the select. # For non-autocreated 'through' models, can't assume we are # dealing with PK values. @@ -1475,10 +1478,10 @@ def create_forward_many_to_many_manager(superclass, rel, reverse): def _add_items( self, source_field_name, target_field_name, *objs, through_defaults=None ): - # source_field_name: the PK fieldname in join table for the source object - # target_field_name: the PK fieldname in join table for the target object - # *objs - objects to add. Either object instances, or primary keys - # of object instances. + # source_field_name: the PK fieldname in join table for the source + # object target_field_name: the PK fieldname in join table for the + # target object *objs - objects to add. Either object instances, or + # primary keys of object instances. if not objs: return @@ -1544,10 +1547,10 @@ def create_forward_many_to_many_manager(superclass, rel, reverse): ) def _remove_items(self, source_field_name, target_field_name, *objs): - # source_field_name: the PK colname in join table for the source object - # target_field_name: the PK colname in join table for the target object - # *objs - objects to remove. Either object instances, or primary - # keys of object instances. + # source_field_name: the PK colname in join table for the source + # object target_field_name: the PK colname in join table for the + # target object *objs - objects to remove. Either object instances, + # or primary keys of object instances. if not objs: return |
