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>

<pre><code>questions = Help.objects.all()
filters = {}
if 'question' in ajax_data:
    filters['question'] = ajax_data.get('question')
if 'description' in ajax_data:
    filters['description'] = ajax_data.get('description')
if 'status' in ajax_data:
    filters['status'] = ajax_data.get('status')
if 'created' in ajax_data:
    filters['created'] = ajax_data.get('created')
if 'modified' in ajax_data:
    filters['modified'] = ajax_data.get('modified')
questions = questions.filter(**filters).values('id','question','description','status','created','modified').order_by('-id')
</code></pre>

<p>Check this link <a href="https://docs.python.org/3/glossary.html#term-argument" rel="nofollow">https://docs.python.org/3/glossary.html#term-argument</a></p>

python django