【发布时间】:2013-12-19 16:02:33
【问题描述】:
根据Model 类的the documentation,我可以使用.get() 类函数通过键(如Key 或string)从AppEngine 数据存储中检索一个或多个实体。我有一个模型Entry:
class Model(ndb.Model):
def to_dict(self):
ret = ndb.Model.to_dict(self)
ret['key'] = self.key.urlsafe()
return ret
class Entry(Model):
text = ndb.StringProperty(required=True)
...
您会注意到我自动将实体的密钥添加到我的公共模型子类的 .to_dict() 结果中,这样当它们为客户端序列化为 JSON,然后通过客户端 AJAX 调用发送回服务器时,我可以在数据存储中找到对应的实体(很简单,对吧?)。问题是,我现在正尝试通过以下方式从客户端使用序列化密钥在 Python 中获取这些实体:
entries = Entry.get(entryKeys)
...但我收到以下错误:
type object 'Entry' has no attribute 'get'
Traceback (most recent call last):
...
File "/home/cbehar/dev/dada/handlers.py", line 126, in post
entries = Entry.get(entryKeys)
AttributeError: type object 'Entry' has no attribute 'get'
是文档过时了还是我只是在做一些愚蠢的事情?
我觉得这应该很简单。我可以改用db.get(),但Model.get() 应该有额外的类型检查,在这一点上,我真的只想知道我到底做错了什么。
【问题讨论】:
标签: google-app-engine entity app-engine-ndb