Ticket #11053: django-onetoonefield.patch
File django-onetoonefield.patch, 1.5 KB (added by , 16 years ago) |
---|
-
django/db/models/fields/related.py
188 188 return getattr(instance, self.cache_name) 189 189 except AttributeError: 190 190 params = {'%s__pk' % self.related.field.name: instance._get_pk_val()} 191 rel_obj = self.related.model._base_manager.get(**params) 191 try: 192 rel_obj = self.related.model._base_manager.get(**params) 193 except exceptions.ObjectDoesNotExist: 194 if self.related.field.null == False: 195 raise 196 rel_obj = None 192 197 setattr(instance, self.cache_name, rel_obj) 193 198 return rel_obj 194 199 -
tests/regressiontests/one_to_one_regress/models.py
141 141 >>> Target.objects.exclude(pointer2=None) 142 142 [] 143 143 144 # return None if the related object does not exist and null=True 145 >>> p = Place() 146 >>> p.bar 147 Traceback (most recent call last): 148 ... 149 DoesNotExist: Bar matching query does not exist. 150 >>> p.undergroundbar is None 151 True 152 >>> bar = Bar() 153 >>> bar.place is None 154 Traceback (most recent call last): 155 ... 156 DoesNotExist 157 >>> ubar = UndergroundBar() 158 >>> ubar.place is None 159 True 160 144 161 """}