views:

195

answers:

3

Hi!

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

Thanks

A: 

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

User.all().filter(email = email)
Dominic Rodger
Doesn't work, but thanks anyway:)
Dmitry Gladkov
OK - what error do you get?
Dominic Rodger
'module' object has no attribute 'Query', but that doesn't matter because Django variant of GAE doesn't user django ORM, it uses Datastore API which has different syntax and a lot of restrictions
Dmitry Gladkov
I've updated my answer. Also, I don't think you're getting that error from my code, since it doesn't reference `Query` at all.
Dominic Rodger
A: 

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.

Nick Johnson
+1  A: 

The right answer is: User(email). Thats it:)

Thanks everyone, anyway.

Dmitry Gladkov