Created
March 30, 2015 03:59
-
-
Save tyaslab/fec2d988fadcce5427b5 to your computer and use it in GitHub Desktop.
Django < 1.8 arithmetic aggregate more than one field
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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