1

What I am trying to do is

Sale.objects.values('pro').annotate(total_value = Sum('effective_price')).filter(total_value__gt=Decimal('600.00')).order_by('total_value');

In orm it does not return anything but when I takes it query in SQL and then execute in SQL it returns results as I want. There is a problem with filter as far as I know. I don't know why it is not working even count is working properly when I filter using the annotate variable.

halfer
  • 19,824
  • 17
  • 99
  • 186
  • 2
    Try to solve this step-by-step. Open a Django shell: `./manage.py shell` and try first without the `values('pro')`. Does it works? If not, try without the `Decimal('600.00')`, use only `total_value__gt=600`. If that doesn't work, try without the `filter`. You'll eventually get results and then you try adding things back one-by-one. – Tiago Jan 12 '17 at 21:05
  • Hi tiago, i tried your solution but no luck. result is still empty – dheeraj saini Jan 12 '17 at 21:20
  • i found it might be a bug in django 1.8. Here is the link that i found [link](http://stackoverflow.com/questions/4536535/filtering-with-a-q-object-on-an-annotated-queryset) – dheeraj saini Jan 12 '17 at 21:21
  • This is the raw sql of it. **'SELECT "sale"."pro_id", SUM("sale"."effective_price") AS "total_value" FROM "sale" GROUP BY "sale"."pro_id" HAVING SUM("sale"."effective_price") > 600 ORDER BY "total_value" ASC'**. I executed in sql and it works fine. So what does it mean. is it a bug in django 1.8 ? – dheeraj saini Jan 12 '17 at 21:26
  • 1
    Ok i did it by converting it in float. its working fine now. Thanks – dheeraj saini Jan 12 '17 at 22:17

0 Answers0