How to use request.GET.get() with JsonResponse view - django
i want to create a query base on two dates, i'm using one view for json response, and another view for the template
def dateTimePrice(request):
start = request.GET.get('from')
end = request.GET.get('to')
print(start,end)#print None
if start and end:
datetimes = ImeiInvoice.objects.filter(invoice__created_at__range=(start,end)).annotate(
total_price=Sum(
(F('price')) - F('discount'),output_field=DecimalField(max_digits=20,decimal_places=3))
).annotate(
total_quantity=(
Count('pk')
)
).aggregate(
all_price=Sum(F('total_price')),
all_qnt=Sum(F('total_quantity'))
)
else:
datetimes = ImeiInvoice.objects.all().annotate(
total_price=Sum(
(F('price')) - F('discount'),output_field=DecimalField(max_digits=20,decimal_places=3))
).annotate(
total_quantity=(
Count('pk')
)
).aggregate(
all_price=Sum(F('total_price')),
all_qnt=Sum(F('total_quantity'))
)
return JsonResponse(datetimes,safe=False)
@login_required
def dateTimePriceTemp(request):
return render(request,'myapp/datetimes.html')
and here is my template
<form action="" method="GET">
<div class="col-11 p-1 mt-1 mx-auto text-center row rtl ">
<p class="col-12 col-sm-6 mx-auto text-left row">
<img src="icons/date.svg" class="ml-1" alt="">
from
<input type="date" class="form-control col-9 mr-1" name="from" id="">
</p>
<p class="col-12 col-sm-6 mx-auto text-right row">
<img src="icons/date.svg" class="ml-1" alt="">
to
<input type="date" name="to" class="form-control col-9 mr-1" id="">
</p>
<button type='submit' class="btn btn-info col-8 col-sm-5 col-md-3 mx-auto">search</button>
</div>
</form>
i returned the data with ajax call, it works fine, but i dont know to get from
and to
values from the template!? i much appreciate your helps ..