multi column search in django using ajax
<p>I am working on a listing in django project. The scenario is that When i click on FAQ listing page then it redirects me to the listings where i get all faq. Now i have to search using different keywords. There is total five keywords through which i can search for particular results. Code is</p>

<pre><code>questions = Help.objects.all().filter().values('id','question','description','status','created','modified').order_by('-id')
if 'question' in ajax_data:
    #add filter for question
if 'description' in ajax_data:
    #add filter for description
if 'status' in ajax_data:
    #add filter for status
if 'created' in ajax_data:
    #add filter for created
if 'modified' in ajax_data:
    #add filter for modified
questions = Help.objects.all().filter(#add all conditions here dynamically after applying filters).values('id','question','description','status','created','modified').order_by('-id')
</code></pre>

<p>First when page refresh it executes first query which returns all data, now using ajax filters have to be applied, i have done all ajax code just want logic of this search. Search should perform like if i enter question only it should filter according to question, but if i search using question, status and created filed it should apply filter for all these three keywords.</p>

<p>You can use <code>request.GET.get('filter_name')</code></p>

<p>e.g if you have a filter by title:</p>

<pre><code>query = Model.objects.all()
title = request.GET.get('title')    
if title:
    query = query.filter(title__icontains=title)

...and so on
</code></pre>

<p>note that your url should contain get parameters like <code>http://myurl.com/?title=abc</code></p>

<p><strong>EDIT</strong>
    for one query filter you can use <code>Q</code> object from <code>django.db.models</code>   </p>

<pre><code>filter = Q()
if title:
    filter &amp;= Q(title__icontains=title)
if category:
    filter &amp;= Q(category__icontains=category)
query = query.filter(filter)
</code></pre>

python django