'Validate reference.
Returns:
A valid value.
Raises:
BadValueError for the following reasons:
- Value is not saved.
- Object not of correct model type for reference.'

def validate(self, value):

    if isinstance(value, datastore.Key):
        return value
    if ((value is not None) and (not value.has_key())):
        raise BadValueError(('%s    instance    must    have    a    complete    key    before    it    can    be    stored    as    a    reference' % self.reference_class.kind()))
    value = super(ReferenceProperty, self).validate(value)
    if ((value is not None) and (not isinstance(value, self.reference_class))):
        raise KindError(('Property    %s    must    be    an    instance    of    %s' % (self.name, self.reference_class.kind())))
    return value
