Dmitry Gladkov
Dmitry Gladkov

Reputation: 1365

How to filter users by email in Google App Engine?

I tried User(email = email) and User.all().filter('email = ', email).get(), but both of them don't work for me.

Thanks

Upvotes: 1

Views: 664

Answers (3)

Dmitry Gladkov
Dmitry Gladkov

Reputation: 1365

The right answer is User(email).

Upvotes: 2

Nick Johnson
Nick Johnson

Reputation: 101149

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.

Upvotes: 1

Dominic Rodger
Dominic Rodger

Reputation: 99811

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

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

Upvotes: 0

Related Questions