-1

我想将一些实体转换为新名称。如何查询未定义模型类的实体。

例如我有这样的实体(它简化为更具可读性):

class Some(ndb.model):
  name = ndb.StringProperty()

我想将其重命名为:

class SomeFile(ndb.model):
  name = ndb.StringProperty()

我该怎么做?

如果将重命名SomeSomeFile,将不再Some查询,而只有数据存储中的数据。

4

2 回答 2

1

Kind您可以通过覆盖模型的_get_kind()方法来更改模型类名称并使其指向现有数据存储。

class SomeFile(ndb.Model):
    @classmethod
    def _get_kind(cls):
      return 'Some'

现在您可以SomeFile在 Python 代码中使用,同时将Some实体保留在数据存储区中。

https://cloud.google.com/appengine/docs/python/ndb/modelclass#introduction

于 2015-08-17T13:50:08.090 回答
0

也许我不明白你的问题,但这是你想要的吗?:

for x in Some.query():
    y = SomeFile()
    y.name = x.name
    y.put()
    x.key.delete()

尽管您应该通过批量执行来提高效率。

于 2015-08-17T13:29:39.397 回答