Django, select a maximum from annotated maximums (maximum from a few fields) -
i have question django annotation methods: possible calculate "maximum_discount" of these 3 particular discounts (and sort "maximum_discount")?
product.objects\ .annotate( product_discount=max('discounts__amount'), category_discount=max('category__discounts__amount'), brand_discount=max('brand__discounts__amount') )
try this:
max_discount = max(value key, value in product.objects\ .annotate( # maybe 'aggregate'? product_discount=max('discounts__amount'), category_discount=max('category__discounts__amount'), brand_discount=max('brand__discounts__amount') ) )
Comments
Post a Comment