我有一个GAE数据库实体,如下所示:
class Notification(db.Model):
alert = db.StringProperty()
type = db.StringProperty()
status = db.StringProperty(default="unread", choices=set(["unread", "read"]))
created = db.DateTimeProperty(auto_now_add=True)
modified = db.DateTimeProperty(auto_now=True)
entity = db.StringProperty()
record = db.ReferenceProperty(model.RecordModel)
actor = db.ReferenceProperty(model.Profile)
account = db.ReferenceProperty(model.Account)
...我创建了一个像这样的实体:
notify = model2.Notification(account=account)
notify.alert = message
notify.type = "reminder"
notify.actor = actor
notify.record = record
notify.put()
此调用引发错误 *'通知'对象没有属性'_key'*
nquery = db.Query(model2.Notification).filter('account =', self.session.account).order('-created')
for n in nquery:
try:
_dict = {}
_dict['serverID'] = str(n.key()) #- raises error!
答案 0 :(得分:1)
尝试:
nquery = Notification.all().filter('account =', self.session.account).order('-created')
答案 1 :(得分:0)
我想我已经明白了!我的Notification类中的“entity”属性在python appengine中引起某种命名冲突。更改名称将删除“错误对象没有属性'_key'”错误。去图!