I am calculating size
of the item by multiplying two fields.
Size = order_size_weight x requested_selling_price
I have two approches to do that.
1. Model Property
return float(self.order_size_weight) * float(self.requested_selling_price)
2. Modify QuerySet
return self.extra(
select={"priority": "COALESCE(bm_rank, sales_rank, id)",
"size": "order_size_weight*requested_selling_price", # for oder_by size.
})
Problem
When i use the second
approach, i can not use Annotate
to aggregate or take sum of all the Sizes.
Question
- What is the best / Fast approach to
calculate Size
- Can i use Annotate after using
extra select
EDIT
Solution of 2.
I am able to solve the second problem by Using select extra
before using annotate will help solve the problem.