2

I have an app that stores entities with the owner's email. My models.py looks like this:

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()

When I run this from the interactive console on the development server:

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

I get this:

test@example.com
[]

I feel expect something like this:

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

Can anyone see a problem with my code?

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 に答える