1

我想在 django 中执行以下操作:

假设我有模型称为Account

accountset1 = Account.objects.filter(some query)

accountset2 = Account.objects.filter(some other query)

accounts = Account.objects.filter("account in either of accountset1 accountset2")

我怎样才能做到这一点

4

1 回答 1

2

您可以使用Q对象并在一行中进行查询。

from django.db.models import Q
accounts = Account.objects.filter(Q(some query) | Q(some other query))
于 2012-08-29T06:15:08.137 回答