过滤同一查询Django/Python中两个日期的范围 [英] Filter range from two dates in the same query Django/Python

查看:87
本文介绍了过滤同一查询Django/Python中两个日期的范围的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要一个查询的结果,该查询可以过滤来自同一模型的两个日期.我需要在同一查询中获得距原始日期5天(今天加上4天)的结果和距目标日期(今天加上另外4天)的销售结果.

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.

这是我的代码:

    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?

推荐答案

在您的代码中,请勿在__range中使用方括号.

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))

这篇关于过滤同一查询Django/Python中两个日期的范围的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆