4
我有一個關於django註釋方法的問題: 是否可以計算這3個特定折扣的「maximum_discount」(並按此「maximum_discount」排序) ?Django,從註釋的最大值中選擇一個最大值(最大值來自幾個字段)
Product.objects\
.annotate(
product_discount=Max('discounts__amount'),
category_discount=Max('category__discounts__amount'),
brand_discount=Max('brand__discounts__amount')
)
這裏的每個折扣都是GenericRelations,因此我必須爲產品,類別,品牌選擇折扣,然後從這些折扣中選擇最大值,然後按它們排序(甚至更多 - 將此計算的折扣應用於價格) 。 例如: 產品6 :: 5.00 :: 20.00 :: 25.00 - > 25.00 所以我需要做一個查詢集.. – xwild
我擔心它遠遠落後於Django的queryset可能性。也許你應該嘗試原始查詢。 –