Ticket #5599: onetoone_relation_field_saves.diff
File onetoone_relation_field_saves.diff, 868 bytes (added by , 17 years ago) |
---|
-
db/models/fields/related.py
126 126 def __get__(self, instance, instance_type=None): 127 127 if instance is None: 128 128 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 129 135 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 133 137 134 138 def __set__(self, instance, value): 135 139 if instance is None: