我尝试将数据从csv文件导入到我的本地gae数据存储区。基本上它工作正常但由于某种原因我最终得到datetimeProperty而不是datePoperty。 导入后,所有日期值都包含时间信息(例如2014-11-21 00:00:00)。
有谁知道为什么?
型号:
class DaxValue(db.Model):
date = db.DateProperty(required=True)
close = db.FloatProperty()
prev_close = db.FloatProperty()
high = db.FloatProperty()
low = db.FloatProperty()
opn = db.FloatProperty()
isTradingDay = db.BooleanProperty()
popDate = db.DateTimeProperty()
导入csv的代码:
def pop_db():
with open('table.csv', 'rb') as csvfile:
reader = csv.reader(csvfile, delimiter=',')
next(reader)
for row in reader:
date = datetime.fromtimestamp(mktime(time.strptime(row[0], "%Y-%m-%d"))).date()
open1 = float(row[1])
high = float(row[2])
low = float(row[3])
close = float(row[4])
adj_close = float(row[6])
query = "SELECT * FROM DaxValue WHERE date = DATE('%s')" % str(date)
q = db.GqlQuery(query)
dax_value = q.get()
if not dax_value:
dax_value = DaxValue(date=date, open=open1, close=close, high=high, low=low, isTradingDay=True)
else:
dax_value.close = close
dax_value.opn = open1
dax_value.high = high
dax_value.low = low
dax_value.popDate = datetime.now()
dax_value.isTradingDay = True
dax_value.prev_close = adj_close
dax_value.put()
我很难接受这个查询,即使当天存有一个条目,也会返回无...
yesterday = (datetime.datetime.now() - timedelta(days=1))
query = "SELECT * FROM DaxValue WHERE date = DATE('%s')" % str(yesterday.date())
答案 0 :(得分:1)
Google会在内部将所有日期属性和时间属性存储为日期时间。以下摘自this page:
class DateProperty(verbose_name = None,auto_now = False, auto_now_add = False,...)没有时间的日期;看到 DateTimeProperty以获取更多信息。
值类型:datetime.date;内部转换为datetime.datetime
我同时使用date和datetime属性,这对我来说并没有造成任何问题,即使将它们全部存储为日期时似乎很奇怪。