Hi,
Can anyone help to get the query result for top 2nd row in django with annotate max as shown below. I got max and in that top row now i need to get max of second row. Please help
qs=CommodityDestination.objects.select_related('commodity_price', 'commodity_price__cmdty_uom','commodity_price__ingredient', 'commodity_price__currency')
qs=qs.filter(commodity_price__cmdty_loc=location,plant_id=globeCode).values('commodity_price__ingredient_id').annotate(Max('commodity_price__id'))
maxCommodityPriceIds_c=[ e['commodity_price__id__max'] for e in qs]
qs_f=CommodityDestination.objects.select_related('commodity_price', 'commodity_price__cmdty_uom','commodity_price__ingredient', 'commodity_price__currency')
qs_f=qs_f.filter(commodity_price_id__in=maxCommodityPriceIds_c).exclude(commodity_price__cmdty_uom__isnull=True).exclude(commodity_price__ingredient__code__isnull=True).exclude(commodity_price__ingredient__active_f=False)
qs_f=qs_f.filter(commodity_price__ingredient__id__in = CommodityLocationIngredientRel.objects.values_list('ingredient', flat = True).filter(cmdty_loc=location,active_f=True)).order_by('commodity_price__ingredient__code')
qs_f=qs_f.filter(plant_id=globeCode).annotate(from_date=F('cmdty_dest_a')) # reapply the supply point filter