T
T
TaiLo2021-05-17 05:22:21
Django
TaiLo, 2021-05-17 05:22:21

Is it possible to loop through arguments to a function?

60a1d2a4bf140549138897.png

Here are the arguments in filter Q(title__icontains=true_fuzzy_list[0]) | Q(title__icontains=true_fuzzy_list[1]) for two elements from an array, how can one add arguments for more elements in an array?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
Sergey Gornostaev, 2021-05-17
@pravossos

from functools import reduce
import operator

from django.db.models import Q

conditions = [Q(title__icontains=i) for i in true_fuzzy_list]
results = Item.objects.filter(reduce(operator.or_, conditions ))

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question