Ticket #5599: onetoone_relation_field_saves_v2.diff
File onetoone_relation_field_saves_v2.diff, 1.1 KB (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 cache_name = self.related.field.get_cache_name() 130 try: 131 return getattr(self.related, cache_name) 132 except AttributeError: 133 params = {'%s__pk' % self.related.field.name: instance._get_pk_val()} 134 rel_obj = self.related.model._default_manager.get(**params) 135 setattr(self.related, cache_name, rel_obj) 136 return rel_obj 129 137 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_obj133 134 138 def __set__(self, instance, value): 135 139 if instance is None: 136 140 raise AttributeError, "%s must be accessed via instance" % self.related.opts.object_name