问题
I need the result from a query that filters two dates from the same model. I need to get in the result 5 days (today plus 4 days) from original date and sale from target date (today plus 4 more days) both in the same query.
This is my code:
startdate = datetime.now().date()
endate = datetime.now().date() + timedelta(days=4)
lineas_de_reporte = Reporteots.objects.filter(original_fcd_date__range=[startdate, endate], target_pdate__range=[startdate, endate])
But I'm not getting the result I want, any idea?
回答1:
In your code, don't use bracket with __range.
startdate = datetime.date().today()
endate = datetime.date().today() + timedelta(days=4)
lineas_de_reporte = Reporteots.objects.filter(original_fcd_date__range=(startdate, endate), target_pdate__range=(startdate, endate))
来源:https://stackoverflow.com/questions/41770797/filter-range-from-two-dates-in-the-same-query-django-python