Is it possible to renaming nested fields using for group by clause?
This query:
paymentitem.objects.filter(payment=p).values('item__vat_tax').annotate(base=models.Sum('price')).order_by('item__vat_tax')
returns expected data:
<QuerySet [{'base': Decimal('41.322'), 'item__vat_tax': 15}, {'base': Dec
imal('483.470'), 'item__vat_tax': 21}]>
I want to rename field 'item__vat_tax' as 'vat'. This query:
paymentitem.objects.filter(payment=p).extra(select={'vat': 'item__vat_tax'}).values('item__vat_tax').annotate(base=models.Sum('price')).order_by('vat')
return the same result but surprisingly ordered by vat too.
If I change the field name inside the value statement, it raise an error.