Fixed #10670: fixed reusing QuerySets previously used in a filter expression. Thanks, Alex Gaynor.

git-svn-id: http://code.djangoproject.com/svn/django/trunk@10357 bcc190cf-cafb-0310-a4f2-bffc1f526a37
This commit is contained in:
Jacob Kaplan-Moss 2009-04-02 01:49:12 +00:00
parent 751234bfd9
commit 25130b9675
2 changed files with 18 additions and 3 deletions

View File

@ -196,7 +196,7 @@ class BaseQuery(object):
obj.distinct = self.distinct obj.distinct = self.distinct
obj.select_related = self.select_related obj.select_related = self.select_related
obj.related_select_cols = [] obj.related_select_cols = []
obj.aggregates = self.aggregates.copy() obj.aggregates = deepcopy(self.aggregates)
if self.aggregate_select_mask is None: if self.aggregate_select_mask is None:
obj.aggregate_select_mask = None obj.aggregate_select_mask = None
else: else:
@ -2366,4 +2366,3 @@ def add_to_dict(data, key, value):
data[key].add(value) data[key].add(value)
else: else:
data[key] = set([value]) data[key] = set([value])

View File

@ -259,6 +259,23 @@ FieldError: Cannot resolve keyword 'foo' into field. Choices are: authors, conta
>>> Book.objects.annotate(Count('publisher')).values('publisher').count() >>> Book.objects.annotate(Count('publisher')).values('publisher').count()
6 6
>>> publishers = Publisher.objects.filter(id__in=(1,2))
>>> publishers
[<Publisher: Apress>, <Publisher: Sams>]
>>> publishers = publishers.annotate(n_books=models.Count('book'))
>>> publishers[0].n_books
2
>>> publishers
[<Publisher: Apress>, <Publisher: Sams>]
>>> books = Book.objects.filter(publisher__in=publishers)
>>> books
[<Book: Practical Django Projects>, <Book: Sams Teach Yourself Django in 24 Hours>, <Book: The Definitive Guide to Django: Web Development Done Right>]
>>> publishers
[<Publisher: Apress>, <Publisher: Sams>]
""" """
} }
@ -307,4 +324,3 @@ if settings.DATABASE_ENGINE != 'sqlite3':
""" """