0

I have a GAE database entity that looks like this:

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)

... and I create an entity like so:

notify = model2.Notification(account=account)
notify.alert = message
notify.type = "reminder"
notify.actor = actor
notify.record = record
notify.put() 

This call raises an error *'Notification' object has no attribute '_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! 
4

2 回答 2

1

尝试:

nquery = Notification.all().filter('account =', self.session.account).order('-created') 
于 2012-09-11T10:44:34.203 回答
0

我想我已经想通了!我的 Notification 类中的“实体”属性导致 python appengine 中的某种命名冲突。更改名称会删除“错误对象没有属性 '_key'”错误。去搞清楚!

于 2012-09-12T13:30:04.043 回答