我想在 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")
我怎样才能做到这一点
我想在 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")
我怎样才能做到这一点
您可以使用Q
对象并在一行中进行查询。
from django.db.models import Q
accounts = Account.objects.filter(Q(some query) | Q(some other query))