I
I
Ihor2020-12-21 23:38:18
Django
Ihor, 2020-12-21 23:38:18

django ORM query not working properly?

Hi
i have a sql query

SELECT stock_id, consignment_id, SUM(qty), SUM(cost) 
    FROM warehouse_regсonsignmentproduct
    Where product_id = '1'
    Group BY  stock_id, consignment_id
    Having SUM(qty) > 0


I tried to rewrite it with Django query:

regСonsignmentProduct.objects
        .filter(product='1')
        .order_by('period')
        .values('stock', 'consignment')
        .annotate(total_qty=Sum('qty'), total_cost=Sum('cost'))
        .filter(total_qty__gt=0)

But it doesn't return the correct result. Maybe someone knows where my mistake is?

Thanks!

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question