Fixed #14334 -- Query comparision now check for object types.

Ok I will extend the patch to cover this aspect and make a separate function.
I don't think that it is possible to implement it in `related.py` because when backward relation are used in querying, then we don't have the lhs field class available.