问题
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