python - 在 Google App Engine 中,如何选择不存在属性的实体?

标签 python google-app-engine

使用 GAE 的 python 版本并从 db.Model 扩展模型,如何获取属性等于 None 或不存在的实体?

#This works
#Fetch 10 entities where duration == 0.0
entities = MyModel.all().filter('duration = ', 0.0).fetch(10)

#This doesn't. How can I do the equivalent?
#Fetch 10 entities where duration == None
entities = MyModel.all().filter('duration = ', None).fetch(10)

最佳答案

您有没有 duration 属性的实体(无法过滤,因为索引无法引用它们)和 duration 设置为 None 的实体(可以过滤) .

由于您更改了 MyModel 架构,因此您应该修复没有 duration 属性存储的实体,如下所示:

entities = MyModel.all()
for entity in entities :
  if not entity.duration :
    entity.duration = None
    entity.put()

看看appengine-mapreduce库来完成这个长时间运行的任务。

关于python - 在 Google App Engine 中,如何选择不存在属性的实体?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4106500/

相关文章:

google-app-engine - 谷歌应用引擎评论并在 html View 中检查开发环境

Python boolean 比较: False == not(True) SyntaxError

google-app-engine - App Engine 网址映射

google-app-engine - Google App Engine - 将 HTTP 重定向到 HTTPS

python - 通过应用程序引擎的 FTP 使用 Python 允许连接但超时响应

python - 多处理与运行多个 Python 解释器

python - 如何在 Python 中管理 Google API 错误

python - 使用默认回退选项过滤列表值

python - 包含 100000 个元素的列表上的奇怪行为

python - 使用关键字参数在 GAE ndb 中查询