I am trying to query all the objects in a model that have a positive value in one particular field.
I have not been able to find anywhere whether there is a way to use greater than
signs in django. I have tried doing by sorting the column that interests me and removing the 0 values in that column in order to the overcome the greater than. First it seems over complicated, and second it does not work.
here is the query:
count_orders = replenishment.objects.order_by(F('StockOnOrder')).desc().exclude('StockOnOrder' = 0)
I also need to count the positive rows in this field and it does not work either as following:
count_orders = replenishment.objects.order_by(F('StockOnOrder')).desc().exclude('StockOnOrder' = 0).count()
both give me the error:
keyword can't be an expression
I am wondering if by chance this is the proper way to do it, or if there is something more intuitive and simple.
你应该使用 gt。
model.objects.filter(your_field__gt=0)
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.