Ticket #13839: 13839_1.diff

File 13839_1.diff, 830 bytes (added by Shaun Cutts, 14 years ago)
  • django/db/models/fields/related.py

    diff --git a/django/db/models/fields/related.py b/django/db/models/fields/related.py
    index 5830a79..07e90d1 100644
    a b class SingleRelatedObjectDescriptor(object):  
    219219        if instance is None:
    220220            return self
    221221        try:
    222             return getattr(instance, self.cache_name)
     222            rel_obj = getattr(instance, self.cache_name)
     223            if rel_obj is None:
     224                rmod = self.related.model
     225                raise rmod.DoesNotExist( 'related %s does not exist' % rmod.__name__ )
     226            return rel_obj
    223227        except AttributeError:
    224228            params = {'%s__pk' % self.related.field.name: instance._get_pk_val()}
    225229            db = router.db_for_read(self.related.model, instance=instance)
    226230
Back to Top