如何在查询集中使用OR过滤条件? [英] How to use OR filter condition in queryset?
本文介绍了如何在查询集中使用OR过滤条件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何在查询集中添加其他过滤条件?
How to add other filter condition in queryset?
通常,我只能使用以下条件进行过滤:
In general, I only can filter with one condition like bellow:
queryset = PhysicalServerTask.objects.filter(task_status=TASK_STATUS.GOOD)
我们可以使用其他条件(例如和
)进行过滤吗?
Can we filter with another condition like and
?
我想过滤 tast_status
等于 TASK_STATUS.GOOD
或 TASK_STATUS.WELL
.
该怎么办?
我知道我可以过滤 TASK_STATUS.GOOD
和 TASK_STATUS.WELL
,然后将它们合并.但是,如果有更好的方法可以访问它呢?
I know I can filter TASK_STATUS.GOOD
and TASK_STATUS.WELL
, then merge them. But if there is a better way to access that?
推荐答案
您可以为 .filter
函数添加更多条件.应该是
You can add more condition for the .filter
function. It should be;
PhysicalServerTask.objects.filter(
task_status__in=[TASK_STATUS.GOOD, TASK_STATUS.WELL])
这篇关于如何在查询集中使用OR过滤条件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文