Hello why use raw?
query_results = Prescription.objects.filter(date__range=[fromdate,todate])
if you have any problem with performance hit database use select_related or
used m2m field use prefect_related
https://docs.djangoproject.com/en/4.1/ref/models/querysets/

best!

On Fri, Sep 9, 2022 at 7:48 AM tech george <techgeor...@gmail.com> wrote:

> Hello friends!
>
> I am trying to give users an easier way to filter data by date range.
>
> My views.py code is as below, but unfortunately, it is hiding data without
> applying the filter whenever I try to use if, else statements.
>
> Please advise what I might be doing wrong.
>
> views.py
>
> ef referralsReports(request):
>     if request.method=="POST":
>         fromdate = request.POST.get('fromdate')
>         todate = request.POST.get('todate')
>         searchresults = Prescription.objects.raw('select 
> id,description,prescribe,ailment,ailment_2,ailment_3,'
>                                                  
> 'sickOff,referral,date_precribed,nurse_id,patient_id_id,'
>                                                  'non_work_related_sickOff 
> from pharmacy_prescription where date_precribed '
>                                                  'between "'+str(fromdate)+'" 
> and "'+str(todate)+'"')
>         return render(request, 
> 'pharmacist_templates/reports/referrals_report.html', {"data": searchresults})
>
>     else:
>         displaydata = 
> Prescription.objects.filter(nurse=request.user.pharmacist).order_by('-id')
>         return render(request, 
> 'pharmacist_templates/reports/referrals_report.html', {"data":displaydata})
>
>
> template
>
> [image: image.png]
>
>
> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to django-users+unsubscr...@googlegroups.com.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/django-users/CADYG20Go5PXJRP-MGJ07M36ftSaQ6WJVjYg_p4UYB9UUWge-LA%40mail.gmail.com
> <https://groups.google.com/d/msgid/django-users/CADYG20Go5PXJRP-MGJ07M36ftSaQ6WJVjYg_p4UYB9UUWge-LA%40mail.gmail.com?utm_medium=email&utm_source=footer>
> .
>


-- 
att.
Carlos Rocha

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CAM-7rO3UTB%2Bm7gYzfQ_RB%2BDnDWetnO3E18knFuLPJAU%2BBQrbLw%40mail.gmail.com.

Reply via email to