Annotations with nested Sums

105 views
Skip to first unread message

Marc Aymerich

unread,
Jul 10, 2015, 12:38:56 PM7/10/15
to django-users
Hi,
I need to do some annotations that require a nested sumation,
I have Bills that have Lines that in turn have Sublines: Bill -> Line -> SubLine
In order to calculate the total bill price I need to add all sublines
of every line, and then all lines of a bill.

queryset.annotate(
total=Sum(F('lines__total') + Sum(F('lines__sublines__total')))
)

But I get an AttributeError: 'CombinedExpression' object has no attribute 'name'

Is there any other way to perform this calculation (adding two levels
of nested totals)?.


thanks!
--
Marc
Reply all
Reply to author
Forward
0 new messages