How do I correctly reference Users in GQL queries

2019-07-30 03:24发布

I have a db.Model that has a db.UserProperty. For example:

class Photo( db.Model ):
    owner = db.UserProperty()
    title = db.StringProperty()

When I want to get all the photos for a user, I do this:

photos = Photo.gql( "WHERE owner = USER(:1)", users.get_current_user().nickname() )

This is causing problems, however, between Google and non-Google nicknames. When testing locally, if I use the email address test@example.com, then the nickname is "test@example.com". If I use test@gmail.com, then the nickname is "test". When I test with a Gmail account, I have to append "@gmail.com" to .nickname().

Is there a better way to do this than hard-coding + "@gmail.com" to all my database queries?

1条回答
Rolldiameter
2楼-- · 2019-07-30 04:12

photos = Photo.gql("WHERE owner = :1", users.get_current_user())

查看更多
登录 后发表回答