按自定义过滤 Ndb 查询 属性
Filter Ndb query by custom property
我正在努力:
- 将时区信息从
NdbModel
添加到 end_date
运行 将 end_date
与另一个 date_with_timezone
进行比较的查询,因此我只获取 end_date
在 date_with_timezone
[ 之前的模型=21=]
class PageSchedule(NdbModel):
end_date = ndb.DateTimeProperty()
def end(self):
return self.end_date.replace(tzinfo=pytz.timezone('US/Central'))
然后我尝试从另一个 Class
调用它
schedules = PageSchedule.query(
PageSchedule.end() < date_with_timezone )
).fetch()
但显然不能让它工作。
TypeError: unbound method end() must be called with PageSchedule instance as first argument (got nothing instead)
您只能使用属性进行查询,不能使用它们的功能。然而,有一个简单的解决方案:
schedules = PageSchedule.query(
PageSchedule.end_date < date_in_UTC )
).fetch()
我正在努力:
- 将时区信息从
NdbModel
添加到 运行 将
end_date
与另一个date_with_timezone
进行比较的查询,因此我只获取end_date
在date_with_timezone
[ 之前的模型=21=]class PageSchedule(NdbModel): end_date = ndb.DateTimeProperty() def end(self): return self.end_date.replace(tzinfo=pytz.timezone('US/Central'))
end_date
然后我尝试从另一个 Class
schedules = PageSchedule.query(
PageSchedule.end() < date_with_timezone )
).fetch()
但显然不能让它工作。
TypeError: unbound method end() must be called with PageSchedule instance as first argument (got nothing instead)
您只能使用属性进行查询,不能使用它们的功能。然而,有一个简单的解决方案:
schedules = PageSchedule.query(
PageSchedule.end_date < date_in_UTC )
).fetch()