- android - 多次调用 OnPrimaryClipChangedListener
- android - 无法更新 RecyclerView 中的 TextView 字段
- android.database.CursorIndexOutOfBoundsException : Index 0 requested, 光标大小为 0
- android - 使用 AppCompat 时,我们是否需要明确指定其 UI 组件(Spinner、EditText)颜色
我有一个名为 Version 的模型,如下所示:
from google.appengine.ext import db
import piece
class Version(db.Model):
"A particular version of a piece of writing."
parent_piece = db.ReferenceProperty(piece.Piece, collection_name='versions')
"The Piece to which this version belongs."
note = db.TextProperty()
"A note from the Author about this version."
content = db.TextProperty()
"The actual content of this version of the Piece."
published_on = db.DateProperty(auto_now_add=True)
"The date on which the version was published."
我想使用 Version.get_by_id() 通过 ID 访问 Version 的实例,但此调用总是返回 None。我可以在 Datastore Viewer 中看到它们具有 ID 值,在调试器中,我可以查询它们但不能使用它们:
>>> for each_ver in version.Version.all():
... print each_ver.key().id()
...
34
35
36
31
32
>>> a = version.Version.get_by_id(34)
>>> type(a)
<type 'NoneType'>
我看到这里有很多问题,人们可以按照我的意愿有效地使用 get_by_id(),但他们看不到我看到的结果。
问题可能是每个 Version 实例都是实体组中的子项而不是实体组的根吗?每个 Version 都位于一个看起来像 Member->Piece->Version 的实体组中。如果这是问题所在,有没有一种方法可以在不使用其整个 key 的情况下引用 Version 实体?如果这不是问题,谁能告诉我如何使 get_by_id() 按预期工作?
最佳答案
Could the problem be that each Version instance is a child in an Entity Group rather than a root of an Entity Group?
是的。实体的键包括任何父实体的键。
If that is the problem, is there a way that I can refer to Version entity without using its entire key?
没有。实体仅由其整个键唯一标识,其中包括所有父实体的键。不过,如果您知道其父实体的种类,则可以使用 db.Key.from_path 从 ID 链或 key 名称构造 key 。
关于google-app-engine - get_by_id() 不会返回模型实例,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3072939/
我正在将 Google App Engine 与 webapp2 和 Python 结合使用。 我有一个带有 deleted 字段的 User 模型: class User(ndb.Model):
只是想知道我是否弄错了: get() 操作使用 NDB 缓存,所以这个(章节是 ndb.Model 类): # Get the entity chapter_key = ndb.Key('Book',
通过给定实体 ID,我将通过 models = Model.get_by_id(id) 进行查询。但是,我发现有时它不会集中返回结果。 在 Google App Engine python 中是否有任
我想在当前命名空间之外使用如下内容进行阅读: some_entity = MyModel.get_by_id(some_id_name, namespace='somenamespace') 但是 g
我有一个名为 Version 的模型,如下所示: from google.appengine.ext import db import piece class Version(db.Model):
我用过get_by_id从数据存储中获取实体并且永远不要使用 Ancestor Paths .但是我模型的复杂性使它成为必要。事实上,祖先路径解决了一个大问题,但现在当我尝试 get_by_id 实体
我想知道使用 Model.get_by_key_name() 还是 Model.get_by_id() 获取记录 例如,假设我要返回一些将用于显示记录表的 JSON,并且对于每条记录,都有一个删除该记
使用旧数据库,我可以调用 Model.get_by_id([1, 2, 3]) 来获取实体列表。 Ndb 的 Model.get_by_id 不支持将 id 列表作为参数。复制旧功能的最佳方式是什么?
我正在使用 get_by_id() 从 NDB 读取实体,但我无法让它为属于实体组的实体工作: from google.appengine.ext import ndb class Folder(nd
我正在尝试使 get_by_id() 起作用,但我不确定我在做什么是错误的,或者它实际上不起作用。我期待它返回类似于 ndb.Key('Organization',id).get() 的实体,但两者都
我无法弄清楚如何使用 get_by_id 从 Google App Engine 数据存储区获取对象。这是模型 from google.appengine.ext import db class Ad
运行此代码时,使用相同的 site_id: int_id= int(self.request.get("site_id")) site_draft = SiteDraft.get_by_id(int_
我在 google app engine python ndb 中使用 get_by_id 时遇到问题。 Python 代码 尝试 1 resource = Content.get_by_id(609
我是一名优秀的程序员,十分优秀!