西尼数据的Django时区

2024-04-25 05:34:19 发布

您现在位置:Python中文网/ 问答频道 /正文

我用的是锡格尼特的股票数据。你知道吗

我真的觉得我把日期搞砸了,因为(说不好)它肯定是在处理多个时区(由于多个国家)。你知道吗

如何做好时区?你知道吗

例如,如果有人看到2015年5月25日的数据,就不应该因为忽略时区而显示为24或26日(我目前不管理时区)。你知道吗

我通过csv格式获取数据,然后使用python额外/修改数据,并使用python(而不是Django)保存到db。我不碰日期(除了保存它)。你知道吗

然后我使用Django并将使用StockData模型中的数据。你知道吗

在几分钟内添加代码以显示数据。你知道吗

股票数据模型:

#Saved initially using python(not Django)
# but later I might get StockData objects and save them to populate
#some other fields of that table during save (django, not simple python).
date = models.DateTimeField()
country = models.ForeignKey
company = models.ForeignKey
open, close, high ... values

无论什么时候我想展示我都会做

StockData.objects.filter(...) #No timezone work as of now

我添加了一些随机时区设置.py你知道吗

TIME_ZONE = 'America/New_York' #Dont ask my why NewYork 
#because its just random for now. StockData belongs to some other continent which I cant reveal(let me know if I have to). For now, please assume contient as ABC continent. But that python script is run in US.

Tags: ofto数据djangoobjectsthatmodelssave