我需要查询在一天中的某个时间添加的项目,忽略哪一天。我只保存添加项目时的DateTime
。由DateTimeProperty的时间部分NDB查询
比较datetime.Time
到DateTimeProperty
会给出错误,并且DateTimeProperty没有time()
方法。
我需要查询在一天中的某个时间添加的项目,忽略哪一天。我只保存添加项目时的DateTime
。由DateTimeProperty的时间部分NDB查询
比较datetime.Time
到DateTimeProperty
会给出错误,并且DateTimeProperty没有time()
方法。
唯一的办法是将一天中的时间存储为一个单独的属性。一个int将会很好,你可以将它存储为秒。你可以明确地做到这一点(即在设置日期时间的同时设置time属性,或使用computedproperty自动设置该值。
我有同样的问题(或多或少),我认为唯一的办法就是建立我们自己的日期类模型 事情是这样的:
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()
...
而且我认为,我们应该有其他的方式来做到这一点更容易
。