How to make sum query with type casting and calculation in django views?

I’m calculating the sold items cost in django views and in django signals, and I want to calculate sold items cost on the fly. Price and quantity fields are integers. How can I convert one of them to the float and make sum query with some calculations like these sql queries below?

SELECT sum((t.price::FLOAT * t.quantity) / 1000) as cost FROM public."sold" t;

SELECT t.id, t.price, t.quantity, sum((price::FLOAT * quantity) / 1000) as cost FROM public.”sold” t
GROUP BY t.id;

I expected the output of first query

5732594.000000002

and I expected the output of second query

id price quantity cost

846 1100 5000 5500
790 1500 1000 1500
828 2600 1000 2600
938 1000 5000 5000
753 1500 2000 3000
652 5000 1520 7600

How to make sum query with type casting and calculation in django views?