Дата создания отчета не включена

Я пытаюсь сгенерировать отчет в pdf в Django, но дата отчета не отображается. Как можно включить дату отчета fromdate и todate в заголовок PDF после сохранения дат в модели? Есть ли что-то, что я упустил?

Пожалуйста, смотрите ниже коды. Спасибо

View.py

def GenerateInvoiceAccident(request):
try:
    if request.method == 'POST':
        fromdate = request.POST.get('fromdate')
        todate = request.POST.get('todate')
        report = GenerateReport(user=request.user, fromdate=fromdate, todate=todate, report="Accident Causation PDF")
        report.save()
        
    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_accident = IncidentGeneral.objects.filter(status = 2, date__range=[fromdate, todate ])
    incident_general_accident1 = IncidentGeneral.objects.filter(status = 2,severity='Fatal', date__range=[fromdate, todate ] ).annotate(Count('severity'))
    incident_general_accident2 = IncidentGeneral.objects.filter(status = 2,severity='Damage to Property', date__range=[fromdate, todate ] ).annotate(Count('severity'))
    incident_general_accident3 = IncidentGeneral.objects.filter(status = 2,severity='Non-Fatal', date__range=[fromdate, todate ] ).annotate(Count('severity'))
    incident_general_classification = IncidentGeneral.objects.filter(status = 2, severity="Damage to Property", date__range=[fromdate, todate ]).distinct('accident_factor')
    incident_general_collision = IncidentGeneral.objects.filter(status = 2, severity="Damage to Property", date__range=[fromdate, todate ]).distinct('accident_factor') #you can filter using order_id as well
    
    
    report1 = GenerateReport.objects.all().order_by('-created_at')[:1]
except:
    return HttpResponse("505 Not Found")
data = {
    'incident_general_accident': incident_general_accident,
    'incident_general_classification': incident_general_classification,
    'incident_general_collision': incident_general_collision,
    'incident_general_accident1': incident_general_accident1,
    'incident_general_accident2': incident_general_accident2,
    'incident_general_accident3': incident_general_accident3,
    'report1':report1
        # 'amount': order_db.total_amount,
}
pdf = render_to_pdf('pages/generate_report_pdf_accident.html', data)
    #return HttpResponse(pdf, content_type='application/pdf')

    # force download
if pdf:
    response = HttpResponse(pdf, content_type='application/pdf')
    filename = "Accident_Causation.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")
return render(request, 'pages/generate_report_sa.html')

модели

class GenerateReport(models.Model):
user = models.ForeignKey(User, on_delete=models.CASCADE, null=True)
fromdate = models.DateField(blank=True, null=True)
todate = models.DateField(blank=True, null=True)
report = models.CharField(max_length=250)
created_at = models.DateTimeField(auto_now_add=True)
updated_at = models.DateTimeField(auto_now=True)

def __str__(self):
    return self.report

html

<header class="clearfix">
<div id="logo" style="display:flex; justify-content:center; align-items:center;">
  <img src="static/images/qc-signos.png" width="300px" height="auto" alt=""
                                title="" />

  <br>
  <br>
</div>
<h3>Accident Causation vs Severity</h3>

<div id="company" class="clearfix">
</div>
<br>
<br>
 <table class="table" style="width:100%">
  <h3>{{report1.fromdate}} {{report1.todate}}</h3>
      <thead>
          <tr>
            <th scope="col">DATE</th>
            <th scope="col">TIME</th>
            <th scope="col">ADDRESS</th>
              <th scope="col">ACCIDENT CAUSATION</th>
              {% comment %} <th scope="col">ACCIDENT CAUSATION SUB-CATEGORY</th> {% endcomment %}
              <th scope="col">SEVERITY</th>
          </tr>
      </thead>
      <tbody>
          {% for i in incident_general_accident %}
        
          <tr>
            <td scope="row">{{i.date}}</td>
            <td scope="row">{{i.time}}</td>
            <td scope="row">{{i.address}}</td>
              <td scope="row">{{i.accident_factor.category}}</td>
              {% comment %} <td scope="row">{{i.accident_subcategory.sub_category}}</td> {% endcomment %}
              <td>{{i.severity}}</td>
             
       
          </tr>
          {% endfor %}

          <tr>
              <td scope="row"></td>
              <td>TOTAL: </td>
              <td>{{incident_general_accident | length}}</td>
              
          </tr>
      </tbody>
  </table> 

  

</div>
<div class="table-container" style="overflow-x:auto">


   <h3>SUMMARY</h3>

   <table class="table" style="width:100%">
     <thead>
         <tr>
             <th scope="col">DAMAGE TO PROPERTY</th>
             <th scope="col">FATAL</th>
             <th scope="col">NON-FATAL</th>
         </tr>
     </thead>
     <tbody>
         
       
         <tr>
             <td scope="row">{{incident_general_accident2 | length}}</td>
             <td scope="row">{{incident_general_accident1 | length}}</td>
             <td>{{incident_general_accident3 | length}}</td>
            
      
         </tr>
        

         {% comment %} <tr>
             <td scope="row"></td>
             <td>TOTAL: </td>
             <td>{{incident_general_accident | length}}</td>
             
         </tr> {% endcomment %}
     </tbody>
 </table> 

   

 </div>
Вернуться на верх