开发者

How to filter users by email in Google App Engine?

开发者 https://www.devze.com 2022-12-08 01:48 出处:网络
I tried User(email = ema开发者_Python百科il) and User.all().filter(\'email = \', email).get(), but both of them don\'t work for me.

I tried User(email = ema开发者_Python百科il) and User.all().filter('email = ', email).get(), but both of them don't work for me.

Thanks


The right answer is User(email).


You need to construct a User object for the user you want to filter by - I'm assuming here that your model includes a UserProperty. For example:

User.all().filter("user =", User(email)).get()

Failing that, you can denormalize, and store the user's email in an additional StringProperty field.

If you're using the user as the primary key on your entity, though, you'd be better off fetching the user___id from the User object and using it as the key name for the entity when you create it. Then, you can fetch it with User.get(user_id), which is much more efficient than doing a query.


Assuming you're using the Django variant of GAE, try:

User.all().filter(email = email)
0

精彩评论

暂无评论...
验证码 换一张
取 消