mirror of
https://github.com/django/django.git
synced 2025-09-26 12:09:19 +00:00
Fixed #9997 -- Fixed use of ValuesQuerySets as rvalues in filters.
Previous behaviour was pretty stupid. Let's never speak of it again. New behaviour both works and is documented. git-svn-id: http://code.djangoproject.com/svn/django/trunk@9759 bcc190cf-cafb-0310-a4f2-bffc1f526a37
This commit is contained in:
parent
14b3f03015
commit
d579e716fe
3 changed files with 46 additions and 0 deletions
|
@ -798,6 +798,20 @@ class ValuesQuerySet(QuerySet):
|
|||
|
||||
super(ValuesQuerySet, self)._setup_aggregate_query()
|
||||
|
||||
def as_sql(self):
|
||||
"""
|
||||
For ValueQuerySet (and subclasses like ValuesListQuerySet), they can
|
||||
only be used as nested queries if they're already set up to select only
|
||||
a single field (in which case, that is the field column that is
|
||||
returned). This differs from QuerySet.as_sql(), where the column to
|
||||
select is set up by Django.
|
||||
"""
|
||||
if ((self._fields and len(self._fields) > 1) or
|
||||
(not self._fields and len(self.model._meta.fields) > 1)):
|
||||
raise TypeError('Cannot use a multi-field %s as a filter value.'
|
||||
% self.__class__.__name__)
|
||||
return self._clone().query.as_nested_sql()
|
||||
|
||||
class ValuesListQuerySet(ValuesQuerySet):
|
||||
def iterator(self):
|
||||
self.query.trim_extra_select(self.extra_names)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue