'Check whether the object passed while querying is of the correct type.
If not, raise a ValueError specifying the wrong object.'

def check_query_object_type(self, value, opts, field):

    if hasattr(value, '_meta'):
        if (not check_rel_lookup_compatibility(value._meta.model, opts, field)):
            raise ValueError(('Cannot    query    "%s":    Must    be    "%s"    instance.' % (value, opts.object_name)))
