[英]Django model where field is based on another field unless specified otherwise
[英]where condition based on another field value in django
我有以下結構的表:
==========================================
itemName minPrice maxPrice curPrice
==========================================
A 10 20 8
B 15 25 12
c 20 30 25
在mysql中就是這樣
select * from Items where curPrice<minPrice
但是我想要在Django中應該返回“ A,B項目名稱結果”。
我已經嘗試使用過濾器,但無法獲得成功。
要將過濾器中的值與模型上的另一個字段進行比較,請使用F()
對象:
from django.db.models import F
Item.objects.filter(curPrice__lt=F('minprice'))
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.