Ticket #9023: onetoone_cache_clear.diff
File onetoone_cache_clear.diff, 2.2 KB (added by , 16 years ago) |
---|
-
fields/related.py
114 114 self.set_attributes_from_rel() 115 115 related = RelatedObject(other, cls, self) 116 116 if not cls._meta.abstract: 117 self. contribute_to_related_class(other, related)117 self.related_object_descriptor = self.contribute_to_related_class(other, related) 118 118 119 119 def get_db_prep_lookup(self, lookup_type, value): 120 120 # If we are doing a lookup on a Related Field, we must be … … 271 271 (value, instance._meta.object_name, 272 272 self.field.name, self.field.rel.to._meta.object_name)) 273 273 274 # Remove the cache for the related field in the related object 275 related_object = getattr(instance, self.field.name) 276 if related_object: 277 cache_name = self.field.related_object_descriptor.cache_name 278 if hasattr(related_object, cache_name): 279 delattr(related_object, cache_name) 280 274 281 # Set the value of the related field 275 282 try: 276 283 val = getattr(value, self.field.rel.get_related_field().attname) … … 719 726 cls._meta.duplicate_targets[self.column] = (target, "o2m") 720 727 721 728 def contribute_to_related_class(self, cls, related): 722 setattr(cls, related.get_accessor_name(), ForeignRelatedObjectsDescriptor(related)) 729 descriptor = ForeignRelatedObjectsDescriptor(related) 730 setattr(cls, related.get_accessor_name(), descriptor) 731 return descriptor 723 732 724 733 def formfield(self, **kwargs): 725 734 defaults = { … … 758 767 super(OneToOneField, self).__init__(to, to_field, OneToOneRel, **kwargs) 759 768 760 769 def contribute_to_related_class(self, cls, related): 761 setattr(cls, related.get_accessor_name(), 762 SingleRelatedObjectDescriptor(related)) 770 descriptor = SingleRelatedObjectDescriptor(related) 771 setattr(cls, related.get_accessor_name(), descriptor) 772 return descriptor 763 773 764 774 def formfield(self, **kwargs): 765 775 if self.rel.parent_link: