def __get__(self, instance, instance_type=None):
        if instance is None:
            return self
        try:
            rel_obj = getattr(instance, self.cache_name)
        except __HOLE__:
            val = getattr(instance, self.field.attname)
            if val is None:
                rel_obj = None
            else:
                other_field = self.field.rel.get_related_field()
                if other_field.rel:
                    params = {'%s__%s' % (self.field.rel.field_name, other_field.rel.field_name): val}
                else:
                    params = {'%s__exact' % self.field.rel.field_name: val}
                qs = self.get_query_set(instance=instance)
                # Assuming the database enforces foreign keys, this won't fail.
                rel_obj = qs.get(**params)
                if not self.field.rel.multiple:
                    setattr(rel_obj, self.field.related.get_cache_name(), instance)
            setattr(instance, self.cache_name, rel_obj)
        if rel_obj is None and not self.field.null:
            raise self.field.rel.to.DoesNotExist
        else:
            return rel_obj
dataset/ETHPy150Open AppScale/appscale/AppServer/lib/django-1.5/django/db/models/fields/related.py/ReverseSingleRelatedObjectDescriptor.__get__