diff --git a/django/db/models/query.py b/django/db/models/query.py index 79562ed77d..9c3cf48e88 100644 --- a/django/db/models/query.py +++ b/django/db/models/query.py @@ -871,6 +871,8 @@ class ValuesListQuerySet(ValuesQuerySet): # 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..023cf8d07b 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] +>>> qs = Book.objects.values_list('price').annotate(count=Count('price')).order_by('-count', 'price') +>>> list(qs) == [(Decimal('29.69'), 2), (Decimal('23.09'), 1), (Decimal('30'), 1), (Decimal('75'), 1), (Decimal('82.8'), 1)] +True """}