Ticket #5599: onetoone_relation_field_saves.diff

File onetoone_relation_field_saves.diff, 868 bytes (added by Vadim Fint, 17 years ago)

Fast fixup.

  • db/models/fields/related.py

     
    126126    def __get__(self, instance, instance_type=None):
    127127        if instance is None:
    128128            raise AttributeError, "%s must be accessed via instance" % self.related.opts.object_name
     129        try:
     130            self.__cached_rel_obj
     131        except AttributeError:
     132            params = {'%s__pk' % self.related.field.name: instance._get_pk_val()}
     133            rel_obj = self.related.model._default_manager.get(**params)
     134            self.__cached_rel_obj = rel_obj
    129135
    130         params = {'%s__pk' % self.related.field.name: instance._get_pk_val()}
    131         rel_obj = self.related.model._default_manager.get(**params)
    132         return rel_obj
     136        return self.__cached_rel_obj
    133137
    134138    def __set__(self, instance, value):
    135139        if instance is None:
Back to Top