Filter range from two dates in the same query Django/Python

拟墨画扇 提交于 2020-01-26 04:14:21

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!