2👍
✅
import operator
names = [...]
query = reduce(operator.or_, [Q(name__icontains=name) for name in names])
results = queryset.complex_filter(query)
0👍
I do not know what Q
is in this case, but maybe
import operator
qq = [Q(name__contains=i) for i in name)]
args = reduce(operator.or_, qq)
might help. But as this is the same as Timmy wrote, don’t upvote me, but him.
If not, see at this question here.
- [Answered ]-Where to put REST API in Django
- [Answered ]-Django saying that table does not exist
- [Answered ]-Decouple module error running Django 1.8 project using Django 1.9
- [Answered ]-Django Custom Authentication –
0👍
Here is a pretty satisfying solution. If it is ever of any help to anyone
http://bradmontgomery.blogspot.com/2009/06/adding-q-objects-in-django.html
q = Q(content__icontains=term_list[0]) | Q(title__icontains=term_list[0])
for term in term_list[1:]:
q.add((Q(content__icontains=term) | Q(title__icontains=term)), q.connector)
stories = stories.filter(q)
- [Answered ]-Django admin form field – display objecy-dependent query results in a select box
- [Answered ]-Order template when using _set.all
- [Answered ]-Understand models relationship . Its python, Django my q is ideologic
- [Answered ]-How do I reset template loader cache in Django 1.9?
- [Answered ]-NoReverseMatch arguments django
Source:stackexchange.com