2

我有一个应用程序,它用所有者的电子邮件存储实体。我的 models.py 看起来像这样:

from google.appengine.ext import db
from google.appengine.api import users

class GenericModel(db.Model):
    '''GenericModel is inherited by other model definitions.'''
    DateAdded = db.DateTimeProperty(auto_now_add = True)
    owner = db.UserProperty()

class CASentry(GenericModel):
    description = db.TextProperty()
    date = db.DateProperty()
    hours = db.FloatProperty()
    location = db.StringProperty()

当我从开发服务器上的交互式控制台运行它时:

from google.appengine.ext import db
t = db.GqlQuery('''SELECT * FROM CASentry''').fetch(1)[0]
print t.owner

t = db.GqlQuery('''SELECT * FROM CASentry where owner = 'test@example.com' ''').fetch(1)
print t

我明白了:

test@example.com
[]

我觉得期待这样的事情:

test@example.com
[<models.CASentry object at 0x123456>]

谁能看到我的代码有问题?

4

2 回答 2

1

您应该提供User而不是字符串:

t = db.GqlQuery("SELECT * FROM CASentry where owner = :owner", owner=User(email="test@example.com")).fetch(1)
于 2012-12-10T10:04:47.910 回答
0

您可以直接在 GQL 中转换为 User:

SELECT * FROM CASentry where owner = USER('test@example.com')
于 2012-12-10T10:10:55.533 回答