title: Django search / filter across multiple models
body: <p>In my Django website, I'm trying to create a search bar on my homepage that returns results that are stored in two different models(Articles, Jobs)</p>
  <p>Currently, I get an empty result set when I search using this code:</p>
  <p>In models.py,</p>
  <pre><code>class Articles(models.Model):
      objects = None
  
      news_title = models.CharField(db_column=&quot;title&quot;, max_length=400)
      news_url = models.URLField(db_column=&quot;link&quot;, max_length=400)
      image_link = models.CharField(db_column=&quot;image&quot;, max_length=400)
      published_date = models.CharField(db_column=&quot;published_date&quot;, max_length=400)
  
      class Meta:
          managed = False
          db_table = &quot;articles&quot;
  
      def __str__(self):
          return self.news_title
  
  
  class Jobs(models.Model):
      objects = None
  
      company = models.CharField(db_column='company', max_length=100)
      job_title = models.CharField(db_column='job_title', max_length=300)
      experience = models.CharField(db_column='experience', max_length=300)
      edu_level = models.CharField(db_column='edu_level', max_length=50)
  
      class Meta:
          managed = False
          db_table = &quot;job_list&quot;
  
      def __str__(self):
          return self.job_title
  </code></pre>
  <p>In views.py,</p>
  <pre><code>class SearchView(ListView):
      template_name = 'blog/search_results.html'
  
      def get_queryset(self):
          request = self.request
          query = request.GET.get('q', '')
  
          articles_results = Articles.objects.filter(Q(news_title__icontains=query))
          jobs_results = Jobs.objects.filter(Q(job_title__icontains=query))
  
          context={
              'articles':articles_results,
              'jobs':jobs_results,
          }
  
          return render(request, 'blog/search_results.html', context)
  </code></pre>
  <p>In main_view.html, I'm using this code for creating a search bar:</p>
  <pre><code>&lt;form action=&quot;{%url 'search_results' %}&quot; method=&quot;get&quot; values=&quot;{{request.GET.q}}&quot; class=&quot;search-jobs-form&quot;&gt;
      &lt;div class=&quot;row mb-5&quot;&gt;
           &lt;input name=&quot;q&quot; type=&quot;text&quot; values=&quot;{{request.GET.q}}&quot; placeholder=&quot;search&quot;&gt;
      &lt;/div&gt;
      &lt;button type=&quot;submit&quot;&gt;Search&lt;/button&gt;
  &lt;/form&gt;
  </code></pre>
  <p>And in search_results.html,</p>
  <pre><code>{% block content %}
      {% for job in jobs %}
          &lt;h5&gt;{{job.job_title}}&lt;/h5&gt;
          &lt;p&gt;{{job.company}}&lt;/p&gt;
      {% endfor %}
  
      {% for article in articles %}
          &lt;h5&gt;{{article.news_title}}&lt;/h5&gt;
          &lt;p&gt;{{article.published_date}}&lt;/p&gt;
      {% endfor %}
  {% endblock %}
  </code></pre>