Advertisement
horozov86

2. Product Quantity Ordered

Dec 5th, 2023
800
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.45 KB | None | 0 0
  1. def product_quantity_ordered():
  2.     total_quantity_ordered_products = (
  3.         Product.objects.annotate(
  4.             total_ordered_quantity=Sum('orderproduct__quantity')
  5.         ).exclude(total_ordered_quantity=None).order_by('-total_ordered_quantity')
  6.     )
  7.     result = []
  8.  
  9.     for product in total_quantity_ordered_products:
  10.         result.append(f"Quantity ordered of {product.name}: {product.total_ordered_quantity}")
  11.  
  12.     return "\n".join(result)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement