'Descriptor to allow lazy dereferencing.'

def __get__(self, instance, owner):

    if (instance is None):
        return self
    value = instance._data.get(self.name)
    self._auto_dereference = instance._fields[self.name]._auto_dereference
    if (self._auto_dereference and isinstance(value, DBRef)):
        if hasattr(value, 'cls'):
            cls = get_document(value.cls)
        else:
            cls = self.document_type
        dereferenced = cls._get_db().dereference(value)
        if (dereferenced is None):
            raise DoesNotExist(('Trying    to    dereference    unknown    document    %s' % value))
        else:
            instance._data[self.name] = cls._from_son(dereferenced)
    return super(ReferenceField, self).__get__(instance, owner)
