Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def product_quantity_ordered():
- total_quantity_ordered_products = (
- Product.objects.annotate(
- total_ordered_quantity=Sum('orderproduct__quantity')
- ).exclude(total_ordered_quantity=None).order_by('-total_ordered_quantity')
- )
- result = []
- for product in total_quantity_ordered_products:
- result.append(f"Quantity ordered of {product.name}: {product.total_ordered_quantity}")
- return "\n".join(result)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement