When using Q objects in django queryset for OR condition error occured
<p>I want to use filter with OR condition in django.
For this i want to use Q objects.
My code is this</p>

<pre><code>def product(request):
    try:

        proTitle = request.GET.get('title')
        ProDescription = request.GET.get('description')


    except:
        pass


    list0 = []
    result = Product.objects.filter(Q(title__contains=proTitle ) | Q(description__contains=ProDescription ) )

    for res in result:

        list0.append(res.project_id)
    data ={'title result':list0}
    return HttpResponse(json.dumps(data))



return HttpResponse(json.dumps(data), content_type='application/json')
</code></pre>

<p>When pass all value that is <code>proTitle,ProDescription
it working fine.
If any value is going to none it encounter a error</code>Cannot use None as a query value`
Why this error occured when i am using OR operator into my queryset</p>

<p>I am also try this </p>

<p><code>result = Project.objects.filter(title__contains=proTitle) | Project.objects.filter(description__contains=ProDescription )</code></p>

<p>but same error occured
I am unable to understand actually what is the problem</p>

<p>You may set the defaults of the <code>get</code> method to something other than <code>None</code>, say empty string:</p>

<pre><code>proTitle = request.GET.get('title', '')
ProDescription = request.GET.get('description', '')
funAria = request.GET.get('funAria', '')
femaleReq = request.GET.get('femaleReq', '')
</code></pre>

<p>This is however likely to return all results in the DB when using <code>__contains</code>.</p>

<p>Otherwise you may build the Q functions discarding all <code>None</code> values.</p>

<p>Use this as a guideline: <a href="http://stackoverflow.com/questions/852414/how-to-dynamically-compose-an-or-query-filter-in-django">How to dynamically compose an OR query filter in Django?</a></p>

python django