Django фильтр даты не возвращает ни одного значения
Я пытаюсь сгенерировать pdf файл в django Он работает без фильтра дат, но я хочу, чтобы данные в генерируемом pdf получали только диапазон дат, но я не могу заставить его работать с фильтром дат. На мой взгляд, когда я печатаю fromdate и todate, он не возвращает дату, почему дата не возвращается, даже если я ввожу дату в поле (HTML). Спасибо
Вид
class GenerateInvoiceCollision_i(View):
def get(self, request, *args, **kwargs):
try:
fromdate = request.POST.get('fromdate')
todate = request.POST.get('todate')
print(fromdate, todate)
# incident_general_accident = IncidentGeneral.objects.filter(user_report__status = 2).values('accident_factor__category').annotate(Count('severity'), filter=Q(severity='Damage to Property'))
incident_general_collision = IncidentGeneral.objects.filter(user_report__status = 2, user_report__date__range=["2022-10-13", "2022-10-26"])
incident_general_collision1 = IncidentGeneral.objects.filter(user_report__status = 2,severity='Fatal', user_report__date__range=["2022-10-13", "2022-10-26"] ).annotate(Count('severity'))
incident_general_collision2 = IncidentGeneral.objects.filter(user_report__status = 2,severity='Damage to Property', user_report__date__range=["2022-10-13", "2022-10-26"] ).annotate(Count('severity'))
incident_general_collision3 = IncidentGeneral.objects.filter(user_report__status = 2,severity='Non-Fatal', user_report__date__range=["2022-10-13", "2022-10-26"] ).annotate(Count('severity'))
incident_general_classification = IncidentGeneral.objects.filter(user_report__status = 2, severity="Damage to Property", user_report__date__range=["2022-10-13", "2022-10-26"]).distinct('accident_factor')
except:
return HttpResponse("505 Not Found")
data = {
'incident_general_collision': incident_general_collision,
'incident_general_classification': incident_general_classification,
'incident_general_collision': incident_general_collision,
'incident_general_collision1': incident_general_collision1,
'incident_general_collision2': incident_general_collision2,
'incident_general_collision3': incident_general_collision3,
# 'amount': order_db.total_amount,
}
pdf = render_to_pdf('pages/generate_report_pdf_collision.html', data)
#return HttpResponse(pdf, content_type='application/pdf')
# force download
if pdf:
response = HttpResponse(pdf, content_type='application/pdf')
filename = "Collision_Type.pdf" #%(data['incident_general.id'])
content = "inline; filename='%s'" %(filename)
#download = request.GET.get("download")
#if download:
content = "attachment; filename=%s" %(filename)
response['Content-Disposition'] = content
return response
return HttpResponse("Not found")
Модель
HTML
<!-- Selecte Date Modal -->
<div class="modal fade" id="select_collision" role="dialog">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<h4 class="modal-title">Filter Reports</h4>
<button type="button" class="close" data-dismiss="modal" aria-hidden="true">
<i class="fa-solid fa-xmark"></i>
</button>
</div>
<div class="modal-body">
<form action="{% url 'generateinvoice_collision_i' %}" method="POST">
{% csrf_token %}
<div class="form-group ">
<label>From Date</label>
<input type="date" name="fromdate" class="form-control date" required>
</div>
<div class="form-group">
<label>To Date</label>
<input type="date" name="todate" class="form-control date" required>
</div>
<hr>
<input type="button" class="btn btn-secondary" data-dismiss="modal" value="Cancel">
<input type="submit" class="btn btn-primary" value="Save">
</form>
</div>
</div>
</div>
</div>