Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

374
Views
How to search for multiple keywords over multiple columns in Django

I want to be able to input a list of strings like so:

["searchterm1", "searchterm2", "searchtermN"]

And output all rows from the database where "searchterm1" matches one of the columns OR "searchterm2" matches one of the columns and so on.

Is there a way to do so?

over 4 years ago · Santiago Trujillo
1 answers
Answer question

0

from django.db.models import Q

def search(request):

    list_ = ["searchterm1", "searchterm2", "searchtermN"]

    q_object = Q(title__icontains=list[0]) | Q(description__icontains=list[0])

    for item in list_[1:]:
        q_object.add((Q(title__icontains=item) | Q(description__icontains=item)), q_object.connector)

    queryset = Product.objects.filter(q_object)

reference1 reference2

over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!