Django - 过滤字段大于限制值的对象

问题描述 投票:0回答:2

我想过滤 id 大于我指定的对象。

这就是我正在寻找的:

const LIMIT_ID = 100

bigIdPeople = Person.objects.filter(id > LIMIT_ID)

这可能吗?我应该怎么做? 谢谢!

python django filter django-queryset
2个回答
1
投票

你可以这样做:

bigIdPeople = Person.objects.filter(id_gte=LIMIT_ID)
# this means 'greater than or equal to'
# if you want 'greater than', you can change 'gte' to 'gt'.

0
投票

提醒您需要两个下划线才能使用

gte
Person.objects.filter(id__gte=LIMIT_ID)

© www.soinside.com 2019 - 2024. All rights reserved.