合并两个django queryset,而无需更改订单
我需要对QuerySet进行两种不同的过滤。 QS1 = QS.Filter(name = value)
QS2 = QS.Filter(Equipment_set__name = value)
然后,我需要在不更改订单的情况下连接它们,就像创建它们一样。
qs_result =< querySet [< qs1>,qs2>,]
I need to do two different filtering to the queryset.qs1 = qs.filter(name=value)
qs2 = qs.filter(equipment_set__name=value)
Then I need to connect them without changing the order, just like they were created.
qs_result = <QuerySet [<qs1 >, <qs2>,]
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您可以与
.Union(…)
&nbsp; [django-doc] :这可以多次产生相同的项目。为了防止这种情况,您删除
all = true
:You can work with
.union(…)
[Django-doc]:This can yield the same item multiple times. To prevent that, you remove
all=True
:您可以使用|操作员可以合并两个查询而不更改QuerySet中的实例顺序,
您也可以稍后过滤。
You can use | operator to merge two queries without changing the order of instances in queryset
You can also filter on it later.