如何将 ReferenceProperty 视为 AppEngine 数据存储区中的布尔值?
我有一个模型,它可能引用另一个模型,并且有一个completed_on 日期。
class Game(db.Model):
challenge = db.ReferenceProperty(Challenge, required=False)
completed_on = db.DateTimeProperty(default=None)
我希望能够选择在特定时间段之前完成的所有已完成的挑战游戏。问题是我不能有两个不等式
但是http://code.google.com/appengine/ docs/python/datastore/queries.html 说:
仅允许在一个属性上使用不等式过滤器:
这意味着我无法进行挑战 > '' 和 Completed_on < datetime_value
但是我可以做 is_challenge=True 和completed_on
datetime_value
假设我向数据库添加了一个名为 is_challenge 的新列。考虑到这一点,是否有办法说服数据存储将挑战视为布尔值?
看来不能以这种方式完成,我希望有其他方法可以完成此任务,而不必向模型添加另一列,并且可能还需要与该列一起添加另一个索引。
我希望游戏列表足够大,以至于不想在 python 中为显示的每个页面进行过滤。
I have a model which might reference another model and which has a completed_on date.
class Game(db.Model):
challenge = db.ReferenceProperty(Challenge, required=False)
completed_on = db.DateTimeProperty(default=None)
I'd like to be able to select all of the completed Challenge games that were completed before a certain time period. Problem is I can't have 2 inequalities
But http://code.google.com/appengine/docs/python/datastore/queries.html says:
Inequality Filters Are Allowed on One Property Only:
Which means I can't do challenge > '' and completed_on < datetime_value
However I could do is_challenge=True and completed_on < datetime_value
provided I add a new column to the db called is_challenge. With that in mind, is there someway to convince the datastore to treat challenge as a boolean?
It appears it can't be done this way, and I'm hoping there is some other way to accomplish this without having to add yet another column to the model and probably yet another index to go with that column.
I am expecting the list of games to be large enough to not want to filter it in python for every page displayed.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
正如您所观察到的,做到这一点的唯一方法是添加一个布尔属性来指示是否设置了挑战。您可以使用 计算属性:
The only way to do this is, as you observe, to add a boolean property that indicates if
challenge
is set or not. You can do this with ease by using ComputedProperty: