Ticket #11448: clear_related_cache.diff

File clear_related_cache.diff, 1.5 KB (added by Dennis Kaarsemaker, 15 years ago)
  • django/db/models/fields/related.py

     
    743743        cls._meta.duplicate_targets[self.column] = (target, "o2m")
    744744
    745745    def contribute_to_related_class(self, cls, related):
     746        try:
     747            del(cls._meta._related_objects_cache)
     748        except AttributeError:
     749            pass
    746750        setattr(cls, related.get_accessor_name(), ForeignRelatedObjectsDescriptor(related))
    747751
    748752    def formfield(self, **kwargs):
     
    782786        super(OneToOneField, self).__init__(to, to_field, OneToOneRel, **kwargs)
    783787
    784788    def contribute_to_related_class(self, cls, related):
     789        try:
     790            del(cls._meta._related_objects_cache)
     791        except AttributeError:
     792            pass
    785793        setattr(cls, related.get_accessor_name(),
    786794                SingleRelatedObjectDescriptor(related))
    787795
     
    948956    def contribute_to_related_class(self, cls, related):
    949957        # m2m relations to self do not have a ManyRelatedObjectsDescriptor,
    950958        # as it would be redundant - unless the field is non-symmetrical.
     959        try:
     960            del(cls._meta._related_many_to_many_cache)
     961        except AttributeError:
     962            pass
    951963        if related.model != related.parent_model or not self.rel.symmetrical:
    952964            # Add the descriptor for the m2m relation
    953965            setattr(cls, related.get_accessor_name(), ManyRelatedObjectsDescriptor(related))
Back to Top