I have for example the following lists:
list1 = ['blue', 'red']
list2 = ['green', 'yellow', 'black']
How could i create a query searching for all values (using postgresql).
This will work fine but it's hardcoded for only two values and therefore not handling the varying amount of values of the lists.
entry.objects.annotate(search=SearchVector('colors')).filter(search=SearchQuery('blue') | SearchQuery('red'))
I tried the following to create a 'search_query' string and place it in my query:
for c in color:
search_string += "SearchQuery('" + c +"') | "
search_string = search_string[:-3]
This will result in the following search_strings
SearchQuery('blue') | SearchQuery('red')
SearchQuery('green') | SearchQuery('yellow') | SearchQuery('black')
If i now put this string in my query, it will not work.
entry.objects.annotate(search=SearchVector('colors')).filter(search=search_string)
I appreciate any help to solve this problem.
Link to django postgres search documentation: https://docs.djangoproject.com/en/1.11/ref/contrib/postgres/search/