query Payer objects filter payment__tax__catego ry__id category annota

1
2
3
query = Payer.objects.filter(payment__tax__category__id=category).annotate(amount=Sum('payment__amount'))
query = query.extra(select={'year': 'EXTRACT(YEAR FROM `data_payment`.`date`)','month': 'EXTRACT(MONTH FROM `data_payment`.`date`)'})
query = query.values('inn', 'name', 'amount', 'year','month').order_by('name').distinct()