range filter not working in django
<p>I want to filter my queryset on the basis of two values.</p>

<p>I want result between two numbers.I am trying some code but it is not working .It did not return me proper result.
my code</p>

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

        proTitle = request.GET.get('title')
        ProDescription = request.GET.get('description')
        funAria = request.GET.get('funAria')
        femaleReq = request.GET.get('femaleReq')
        cost_gte = int(request.GET.get('cost_gte'))
        cost_lte = int(request.GET.get('cost_lte'))
    except:
        pass


    if cost_gte and cost_lte :
        list4 = []

        result = Project.objects.filter(budgeted_cost__gte=cost_gte , budgeted_cost__lte=cost_lte )
        print result
        for res in result:

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




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

<p>Some time it returns all product and some time it return none.I cant understand why it is not working.</p>

<p>i also try by range</p>

<pre><code>result = Product.objects.filter(cost__range=(cost_gte,cost_lte))
</code></pre>

<p>but is also behave same.Please guide me what i am doing wrong.</p>

<p>In python when you use <code>range</code> it means <code>range1 &lt;= i &lt; range2</code>, but the filter you are looking for your query is <code>range1 &lt;= i &lt;= range2</code>, so you should not look forward  <code>range</code> instead go </p>

<pre><code> result = Project.objects.filter(budgeted_cost__gte=cost_gte , 
budgeted_cost__lte=cost_lte ) 
</code></pre>

<p>to get desired output.</p>

python django