result =AmazonHistoryPrice.objects.filter(identification=identification,created_at__range=[start_date, end_date]).order_by('created_at').all()
CREATE TABLE "amazon_app_amazonhistoryprice" ("id" integer NOT NULL PRIMARY KEY AUTOINCREMENT, "month" integer NOT NULL, "day" integer NOT NULL, "identification" text NOT NULL, "price" integer NOT NULL, "year" integer NOT NULL, "created_at" datetime NULL);
import requests
url = "127.0.0.1/api/amazon/get_history_price"
payload={'identification': 'B0BF9LBYXJ',
'start_date': '2023-2-20',
'end_date': '2023-2-23'}
files=[
]
headers = {}
response = requests.request("POST", url, headers=headers, data=payload, files=files)
print(response.text)
在 Django 中进行时间范围查询时,确实需要注意一些细节,特别是涉及到日期的比较时。如果你使用的是 Django 的 filter() 方法进行查询,通常是使用 __range 参数指定时间范围,如下所示:
在上述代码中,date__range 参数用于指定查询的时间范围,其中包含 start_date 和 end_date 两个日期。但需要注意的是,这里的时间范围是左闭右闭的,也就是说,查询的结果将包括起始时间和结束时间这两个时间点。
如果你想要查询的时间范围是左闭右开的,即包含起始时间但不包含结束时间,可以将结束时间加上一天,如下所示:
在上述代码中,我们将 end_date 减去一天,得到一个新的日期,作为查询的结束时间。这样就可以实现左闭右开的时间范围查询了。