summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJustin Bronn <jbronn@gmail.com>2010-02-23 05:26:49 +0000
committerJustin Bronn <jbronn@gmail.com>2010-02-23 05:26:49 +0000
commit5546430304f1310e76b217bb3b6e3597d9b87359 (patch)
tree6383d4ff52fdf7dbec1bcf8b359462ae1412ea3b
parentc4699b0b8a8503e552de1fe4f873685f7037b337 (diff)
Fixed #12608 -- No longer return inconsistent results when using `values` 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
-rw-r--r--AUTHORS1
-rw-r--r--django/db/models/query.py3
-rw-r--r--tests/modeltests/aggregation/models.py3
3 files changed, 6 insertions, 1 deletions
diff --git a/AUTHORS b/AUTHORS
index d60a9f72a5..ed27c1ede6 100644
--- a/AUTHORS
+++ b/AUTHORS
@@ -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
diff --git a/django/db/models/query.py b/django/db/models/query.py
index 0424569e0b..7492039b2c 100644
--- a/django/db/models/query.py
+++ b/django/db/models/query.py
@@ -954,7 +954,8 @@ class ValuesListQuerySet(ValuesQuerySet):
# 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
diff --git a/tests/modeltests/aggregation/models.py b/tests/modeltests/aggregation/models.py
index 9ed638ea80..0e8d8816e6 100644
--- a/tests/modeltests/aggregation/models.py
+++ b/tests/modeltests/aggregation/models.py
@@ -362,4 +362,7 @@ True
>>> 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)]
+
"""}