def check_related_objects(self, field, value, opts):
        if field.is_relation:
            # QuerySets implement is_compatible_query_object_type() to
            # determine compatibility with the given field.
            if hasattr(value, 'is_compatible_query_object_type'):
                if not value.is_compatible_query_object_type(opts, field):
                    raise ValueError(
                        'Cannot use QuerySet for "%s": Use a QuerySet for "%s".' %
                        (value.model._meta.model_name, opts.object_name)
                    )
            elif hasattr(value, '_meta'):
                self.check_query_object_type(value, opts, field)
            elif hasattr(value, '__iter__'):
                for v in value:
                    self.check_query_object_type(v, opts, field)
Checks the type of object passed to query relations.
dataset/ETHPy150Open django/django/django/db/models/sql/query.py/Query.check_related_objects