Guest User

Untitled

a guest
Apr 26th, 2018
62
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.47 KB | None | 0 0
  1. class Order(models.Model):
  2. placed_at = models.DateTimeField()
  3. amount = models.DecimalField()
  4.  
  5. Order.objects.annotate(year=TruncYear('placed_at'))
  6. .values('year')
  7. .annotate(total=Sum('amount'))
  8.  
  9. Order.objects.annotate(year=TruncYear('placed_at'))
  10. .values('year')
  11. .aggregate(total=Sum('amount'))
  12.  
  13. <QuerySet [{'year': 2016, 'total': Decimal('20000.00')},
  14. {'year': 2017, 'total': Decimal('30000.00')}]
Add Comment
Please, Sign In to add comment