Permalink
Browse files

Fixed #12608 -- No longer return inconsistent results when using `val…

…ues` and `values_list` in conjunction with `annotate`. Thanks, Charlie Leifer.

git-svn-id: http://code.djangoproject.com/svn/django/trunk@12505 bcc190cf-cafb-0310-a4f2-bffc1f526a37
  • Loading branch information...
1 parent c4699b0 commit 5546430304f1310e76b217bb3b6e3597d9b87359 @jbronn jbronn committed Feb 23, 2010
Showing with 6 additions and 1 deletion.
  1. +1 −0 AUTHORS
  2. +2 −1 django/db/models/query.py
  3. +3 −0 tests/modeltests/aggregation/models.py
View
@@ -289,6 +289,7 @@ answer newbie questions, and generally made Django that much better:
Christopher Lenz <http://www.cmlenz.net/>
lerouxb@gmail.com
Piotr Lewandowski <piotr.lewandowski@gmail.com>
+ Charlie Leifer <coleifer@gmail.com>
Justin Lilly <justinlilly@gmail.com>
Waylan Limberg <waylan@gmail.com>
limodou
@@ -954,7 +954,8 @@ def iterator(self):
# If a field list has been specified, use it. Otherwise, use the
# full list of fields, including extras and aggregates.
if self._fields:
- fields = self._fields
+ fields = list(self._fields) + filter(lambda f: f not in self._fields,
+ aggregate_names)
else:
fields = names
@@ -362,4 +362,7 @@ def __unicode__(self):
>>> Book.objects.filter(pk=1).annotate(mean_age=Avg('authors__age')).values_list('mean_age', flat=True)
[34.5]
+>>> Book.objects.values_list('price').annotate(count=Count('price')).order_by('-count', 'price')
+[(Decimal('29.69'), 2), (Decimal('23.09'), 1), (Decimal('30'), 1), (Decimal('75'), 1), (Decimal('82.8'), 1)]
+
"""}

0 comments on commit 5546430

Please sign in to comment.