Issue
I have three tables :
- First one is product table consist of product details and price
- Second one is customer table with customer details
- And a cart table with customer_id and product _id as foreign key and qty field for quantity of product
I want join cart table and product table and get an additional column called total price that is the result of price in product *qty in cart
How to do this in django orm
I tried f function but it didn't work
Solution
You can try this.
Cart.objects.annotate(total_price=F('product__price')*F('qty'))
Answered By - Prashant Pansuriya
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.