def __get__(self, instance, instance_type=None):
        if instance is None:
            return self

        cache_name = self.field.get_cache_name()
        try:
            return getattr(instance, cache_name)
        except __HOLE__:
            val = getattr(instance, self.field.attname)
            if val is None:
                # If NULL is an allowed value, return it.
                if self.field.null:
                    return None
                raise self.field.rel.to.DoesNotExist
            other_field = self.field.rel.get_related_field()
            relname = self.field.rel.field_name
            if other_field.rel:
                params = {'%s__pk' % relname: val}
            else:
                params = {'%s__exact' % relname: val}

            # Ensure key is sent to the manager
            for field_name in instance._shards.key:
                params[field_name] = getattr(instance, field_name)

            # If the related manager indicates that it should be used for
            # related fields, respect that.
            rel_mgr = self.field.rel.to._default_manager
            rel_obj = rel_mgr.get(**params)
            setattr(instance, cache_name, rel_obj)
            return rel_obj
dataset/ETHPy150Open disqus/sharding-example/sqlshards/db/shards/models.py/PartitionedReverseRelatedObjectDescriptor.__get__