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

Popular posts from this blog

angularjs - ADAL JS Angular- WebAPI add a new role claim to the token -

php - CakePHP HttpSockets send array of paramms -

node.js - Using Node without global install -