Skip to content

Instantly share code, notes, and snippets.

@tyaslab
Created March 30, 2015 03:59
Show Gist options
  • Save tyaslab/fec2d988fadcce5427b5 to your computer and use it in GitHub Desktop.
Save tyaslab/fec2d988fadcce5427b5 to your computer and use it in GitHub Desktop.
Django < 1.8 arithmetic aggregate more than one field
MyModel.objects.aggregate(subtotal=Sum('qty', field='qty * price'))
'qty' ==> fill whatever you want
'qty * price' ==> the real aggregate
annotate is applicable too!
PS:
Django 1.8 can do it using F()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment