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>Your error seems to mean that one of your values is <code>None</code>:</p>

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

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

    except:
        pass

    allQs = Q()
    if proTitle is not None: 
        allQs |= Q(title__contains=proTitle )
    if ProDescription is not None:
        allQs |= Q(description__contains=ProDescription )         
    if funAria is not None:
        allQs |= Q(functional_area__contains=funAria )
    if someIntValue is not None:
        allQs |= Q(some_int_value__gte=someIntValue) # no need to convert someIntValue to an int here as long as you are guaranteed it is unique.
    allQs |= Q(female_candidate=femaleReq )
    list0 = []
    result = Product.objects.filter(allQs)
    for res in result:

        list0.append(res.project_id)
    data ={'title result':list0}
    return HttpResponse(json.dumps(data))
</code></pre>

python django