django - Product of two fields annotation -
i have line in django app this:
db.execute("select sum(price * qty) inventory_orderline order_id = %s", [self.id])
i'd rather perform through models interface provided django, can't find references.
i'm pretty sure can done annotation, examples cover few of them , can't find list in documentation.
i'd this:
self.line_items.annotate(lineprice=product('orderline__price', 'orderline__qty')).aggregate(sum('lineprice'))
can suggest annotation class use perform multiplication? better, link api listing these annotation/aggregation classes?
unfortunately, there aren't enough inbuilt aggregate functions , specifically, there not 1 product.
but doesn't limit in way other having write "non-concise" orm query. case, should able do:
self.line_items.extra(select=("lineprice": "orderline__price*orderline__qty")).aggregate(sum('lineprice'))
Comments
Post a Comment