Ticket #25150: 25150.diff

File 25150.diff, 2.6 KB (added by Tim Graham, 9 years ago)
  • django/db/models/sql/query.py

    diff --git a/django/db/models/sql/query.py b/django/db/models/sql/query.py
    index ba6a50a..0a145fd 100644
    a b class Query(object):  
    10571057        """
    10581058        Checks the type of object passed to query relations.
    10591059        """
    1060         if field.is_relation:
    1061             # QuerySets implement is_compatible_query_object_type() to
    1062             # determine compatibility with the given field.
    1063             if hasattr(value, 'is_compatible_query_object_type'):
    1064                 if not value.is_compatible_query_object_type(opts, field):
    1065                     raise ValueError(
    1066                         'Cannot use QuerySet for "%s": Use a QuerySet for "%s".' %
    1067                         (value.model._meta.model_name, opts.object_name)
    1068                     )
    1069             elif hasattr(value, '_meta'):
    1070                 self.check_query_object_type(value, opts, field)
    1071             elif hasattr(value, '__iter__'):
    1072                 for v in value:
    1073                     self.check_query_object_type(v, opts, field)
     1060        # QuerySets implement is_compatible_query_object_type() to
     1061        # determine compatibility with the given field.
     1062        if hasattr(value, 'is_compatible_query_object_type'):
     1063            if not value.is_compatible_query_object_type(opts, field):
     1064                raise ValueError(
     1065                    'Cannot use QuerySet for "%s": Use a QuerySet for "%s".' %
     1066                    (value.model._meta.model_name, opts.object_name)
     1067                )
     1068        elif hasattr(value, '_meta'):
     1069            self.check_query_object_type(value, opts, field)
     1070        elif hasattr(value, '__iter__'):
     1071            for v in value:
     1072                self.check_query_object_type(v, opts, field)
    10741073
    10751074    def build_lookup(self, lookups, lhs, rhs):
    10761075        """
    class Query(object):  
    11671166            field, sources, opts, join_list, path = self.setup_joins(
    11681167                parts, opts, alias, can_reuse=can_reuse, allow_many=allow_many)
    11691168
    1170             # Prevent iterator from being consumed by check_related_objects()
    1171             if isinstance(value, Iterator):
    1172                 value = list(value)
    1173             self.check_related_objects(field, value, opts)
     1169            if field.is_relation:
     1170                # Prevent iterator from being consumed by check_related_objects()
     1171                if isinstance(value, Iterator):
     1172                    value = list(value)
     1173                self.check_related_objects(field, value, opts)
    11741174
    11751175            # split_exclude() needs to know which joins were generated for the
    11761176            # lookup parts
Back to Top