Assume I have the following model Structure:
class SomeModel(Model):
base_price = DecimalField(....)
commision = DecimalField(....)
I do not want to store total_price in my database for data consistency and wish to calculate it as base_price + commision like
SomeModel.Objects.all().xxxxxx(total_price=base_price + commision)
So my database (Postgresql 9.1) will calculate and return it without recording it on the database and each record in returning queryset will contain total_price that is sum of base_price and commision of that record. also it would be great if I can use filter on calculated field.
How can I do that?
I want something that is similar to following SQL:
select ("base_price" + "commision") as total_price, base_price, commision from some_table;
total_price | base_price | commision
-------------------------------------
15.0 | 14.0 | 1.0
22.0 | 20.0 | 2.0