Ticket #12608: 12608.patch

File 12608.patch, 1.2 KB (added by coleifer, 15 years ago)
  • django/db/models/query.py

    diff --git a/django/db/models/query.py b/django/db/models/query.py
    index 8cb3dbe..31b3333 100644
    a b class ValuesListQuerySet(ValuesQuerySet):  
    954954            # If a field list has been specified, use it. Otherwise, use the
    955955            # full list of fields, including extras and aggregates.
    956956            if self._fields:
    957                 fields = self._fields
     957                fields = list(self._fields) + filter(lambda f: f not in self._fields,
     958                                                     aggregate_names)
    958959            else:
    959960                fields = names
    960961
  • tests/modeltests/aggregation/models.py

    diff --git a/tests/modeltests/aggregation/models.py b/tests/modeltests/aggregation/models.py
    index 9ed638e..0e8d881 100644
    a b True  
    362362>>> Book.objects.filter(pk=1).annotate(mean_age=Avg('authors__age')).values_list('mean_age', flat=True)
    363363[34.5]
    364364
     365>>> Book.objects.values_list('price').annotate(count=Count('price')).order_by('-count', 'price')
     366[(Decimal('29.69'), 2), (Decimal('23.09'), 1), (Decimal('30'), 1), (Decimal('75'), 1), (Decimal('82.8'), 1)]
     367
    365368"""}
Back to Top