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 lerouxb@gmail.com Piotr Lewandowski + Charlie Leifer Justin Lilly Waylan Limberg 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)] + """}