【发布时间】:2015-09-05 19:32:16
【问题描述】:
我需要查询在一天中的某个时间添加的项目,忽略哪一天。我只保存添加项目时的DateTime。
比较datetime.Time 和DateTimeProperty 会出错,并且DateTimeProperty 没有time() 方法。
【问题讨论】:
标签: python google-app-engine datetime google-cloud-datastore app-engine-ndb
我需要查询在一天中的某个时间添加的项目,忽略哪一天。我只保存添加项目时的DateTime。
比较datetime.Time 和DateTimeProperty 会出错,并且DateTimeProperty 没有time() 方法。
【问题讨论】:
标签: python google-app-engine datetime google-cloud-datastore app-engine-ndb
唯一的方法是将一天中的时间存储为单独的属性。一个 int 就可以了,你可以将它存储为秒。您可以显式执行此操作(即在设置日期时间的同时设置时间属性,或使用计算属性自动设置值。
【讨论】:
我有同样的问题(或多或少),我认为唯一的方法是建立我们自己的日期类模型。 像这样的:
class Date(ndb.model):
...
day = ndb.IntegerProperty()
month = ndb.IntegerProperty()
year = ndb.IntegerProperty()
...
class Anything(ndb.Model):
...
dateTime = ndb.StructuredProperty(Date)
...
代替:
class Anything(ndb.Model):
...
dateTime = ndb.DateTimeProperty()
...
但我也认为我们应该有其他方法来更轻松地做到这一点。
【讨论】: