diff options
| author | Malcolm Tredinnick <malcolm.tredinnick@gmail.com> | 2009-01-16 10:59:43 +0000 |
|---|---|---|
| committer | Malcolm Tredinnick <malcolm.tredinnick@gmail.com> | 2009-01-16 10:59:43 +0000 |
| commit | d579e716fef9f06f04861815cf949630d8633271 (patch) | |
| tree | 103cbb5904b5a951be026ecbe2f7ff48a7056004 /docs/ref/models | |
| parent | 14b3f03015081a679a6b5efaf5ea925344ce14c0 (diff) | |
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
Diffstat (limited to 'docs/ref/models')
| -rw-r--r-- | docs/ref/models/querysets.txt | 16 |
1 files changed, 16 insertions, 0 deletions
diff --git a/docs/ref/models/querysets.txt b/docs/ref/models/querysets.txt index 40a47f4c2c..1e32552570 100644 --- a/docs/ref/models/querysets.txt +++ b/docs/ref/models/querysets.txt @@ -1136,6 +1136,7 @@ The above code fragment could also be written as follows:: inner_q = Blog.objects.filter(name__contains='Cheddar').values('pk').query entries = Entry.objects.filter(blog__in=inner_q) + .. versionchanged:: 1.1 In Django 1.0, only the latter piece of code is valid. @@ -1144,6 +1145,21 @@ accesses the internal ``query`` attribute and requires a ``ValuesQuerySet``. If your code doesn't require compatibility with Django 1.0, use the first form, passing in a queryset directly. +If you pass in a ``ValuesQuerySet`` or ``ValuesListQuerySet`` (the result of +calling ``values()`` or ``values_list()`` on a queryset) as the value to an +``__in`` lookup, you need to ensure you are only extracting one field in the +result. For example, this will work (filtering on the blog names):: + + inner_qs = Blog.objects.filter(name__contains='Ch').values('name') + entries = Entry.objects.filter(blog__name__in=inner_qs) + +This example will raise an exception, since the inner query is trying to +extract two field values, where only one is expected:: + + # Bad code! Will raise a TypeError. + inner_qs = Blog.objects.filter(name__contains='Ch').values('name', 'id') + entries = Entry.objects.filter(blog__name__in=inner_qs) + .. warning:: This ``query`` attribute should be considered an opaque internal attribute. |
