Django : How to write Django Group by and where Condition?

放肆的年华 提交于 2021-01-29 13:24:40

问题


I have Django Model with five fields and I mention two fields in serializer class.I need to perform group by and where ClosingStock>0 condition. I have tried with this query but am not getting output.

StoreClosingStock.objects.filter(CLOSING_STOCK__gte="0").values('ITEM_CODE','CLOSING_STOCK')

I have implemented the same query in mysql its working fine .I want the same output in Django

Views.py

class StoreClosingViewset(viewsets.ModelViewSet):
    serializer_class = StoreClosingStockSerializer


    queryset=StoreClosingStock.objects.filter(CLOSING_STOCK__gte=0).values('ITEM_CODE','CLOSING_STOCK')
#The remaining Fields 
#,'BRAND_NAME','STORE_NAME','STORE_CODE','ITEM_NAME')


    filter_backends = [SearchFilter, OrderingFilter]
    search_fields = ['ITEM_CODE', 'CLOSING_STOCK']

来源:https://stackoverflow.com/questions/64351792/django-how-to-write-django-group-by-and-where-condition

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!