我可以在 GAE 的 ndb 中比较两种单一类型的属性吗?

Can I compare two properties of single kind in ndb of GAE?

我可以在 GAE 的 ndb 中比较两个单一种类的属性吗?

class GameLog(ndb.Model):
    duration = ndb.IntegerProperty(default=0)
    time = ndb.IntegerProperty(default=0)

我需要比较这两个属性。我该怎么做?

GameLog.duration > GameLog.time

要完成这种事情,您需要保存(预先计算的)结果,以便为它编制索引,您可以查询它。

为了让这更容易 ndb 给你 Computed Properties:

class GameLog(ndb.Model):
    duration = ndb.IntegerProperty(default=0)
    time = ndb.IntegerProperty(default=0)
    timeout = ndb.ComputedProperty(lambda self: self.duration > self.time)

你不需要自己维护这个 属性,每次你 put() 实体的值都会被计算并保存。现在您可以查询:

GameLog.query(GameLog.timeout == True)