私はクエリセットのリスト(同じモデルのすべてを)持っているの組み合わせ:Djangoは、複数のクエリセット(同一モデル)
results = Entry.objects.all()
result_elms = []
if city_list:
for city in city_list:
result_elms.append(results.filter(address__city__icontains=city))
if county_list:
for county in county_list:
results_elms.append(results.filter(address__county__icontains=county))
#other filters here, daynamically created
#how can I combine all results_elms (querysets) into one?
私は同じモデルからクエリセットを組み合わせること|
演算子を使用することができることを知っています。 しかし、どのようにしてresult_elms
のすべての要素に適用できますか?
from django.db.models import Q
results = Entry.objects.all()
q = Q()
for city in city_list:
q = q | Q(address__city__icontains=city)
results.filter(q)
ドキュメント(https://docs.djangoproject.com/en/1.7/topics/db/queries/#complex-lookups-with-q)が詳細および例があります。
あなたの質問には答えが出るほど詳しくはありません。問題を再現するのに十分な情報と、探している結果の明確な説明( 'if'文も必要ありません)を提供する必要があります。 – thebjorn
'__in'を使って試しましたか?それはあなたを助けるはずです。もっと見る[ここ](https://docs.djangoproject.com/en/1.11/topics/db/queries/#the-pk-lookup-shortcut) – aquaman
@thebjorn何を意味していますか?私の正確な質問はどうすれば応募できますか? (oparatorを結合する)リスト内のすべてのクエリセット。他にどんな情報を提供する必要がありますか? – dease