Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class Order(models.Model):
- placed_at = models.DateTimeField()
- amount = models.DecimalField()
- Order.objects.annotate(year=TruncYear('placed_at'))
- .values('year')
- .annotate(total=Sum('amount'))
- Order.objects.annotate(year=TruncYear('placed_at'))
- .values('year')
- .aggregate(total=Sum('amount'))
- <QuerySet [{'year': 2016, 'total': Decimal('20000.00')},
- {'year': 2017, 'total': Decimal('30000.00')}]
Add Comment
Please, Sign In to add comment