如何在App Engine上的GQL查询中正确引用用户? [英] How do I correctly reference Users in GQL queries on App Engine?
问题描述
我有一个拥有db.UserProperty的db.Model。例如:
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() )
然而,这导致Google与非Google昵称之间出现问题。在本地测试时,如果使用电子邮件地址test@example.com,则昵称为test@example.com。如果我使用test@gmail.com,那么昵称是测试。当我使用Gmail帐户进行测试时,我必须将@ gmail.com附加到.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().
有没有更好的方法可以做到这一点,编码+@ gmail.com到我所有的数据库查询?
Is there a better way to do this than hard-coding + "@gmail.com" to all my database queries?
推荐答案
photos = Photo.gql (WHERE owner =:1,users.get_current_user())
这篇关于如何在App Engine上的GQL查询中正确引用用户?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!