拉風(fēng)的咖菲貓
2023-10-31 14:27:00
我試圖找出 Django 中 __lte 和 __gte 之間的區(qū)別。原因是我正在嘗試創(chuàng)建一個只能在時間范圍內(nèi)使用的日期函數(shù),所以我一直在研究字段查找比較。我查找了幾個文檔https://docs.djangoproject.com/en/3.0/ref/models/querysets/#exclude但沒有得出結(jié)論性的答案。編輯:我了解到lte小于或等于而gte大于或等于這是一些文檔鏈接
3 回答

鴻蒙傳說
TA貢獻1865條經(jīng)驗 獲得超7個贊
根據(jù)https://docs.djangoproject.com/en/dev/ref/models/querysets/
__lte -> Less than or equal
__gte -> Greater than or equal
__lt -> Less than
__gt -> Greater than
QuerySet(foo__lte=10) # foo <= 10
QuerySet(foo__gte=10) # foo >= 10
QuerySet(foo__lt=10) # foo < 10
QuerySet(foo__gt=10) # foo > 10

慕森卡
TA貢獻1806條經(jīng)驗 獲得超8個贊
查找__lte
[Django-doc]意味著您約束字段應(yīng)小于或等于給定值,而__gte
查找 [Django-doc]意味著該字段大于或等于給定值。
例如:
MyModel.objects.filter(field__gte=5)??#?field?≥?5 MyModel.objects.filter(field__lte=5)??#?field?≤?5
添加回答
舉報
0/150
提交
取消