How do I set an entity
's key in my code.
Example, I have a user class
class User(ndb.Model)
email
I want to be able to set email property and query using email property
my_user = User(email='xyz@ab.com')
Above statement sets email property, but Google App Engine generates its own key.
Can I set the key using User(key='xyz@ab.com')
If I can set the key property in a entity, how do I query for an entity using the key
Does this work User.query(key='xyz@ab.com').get()
I realize that I can query using email
as a property, but unfortunately I can't do that in context of a transaction
.
That is the reason I am asking how to get(), set() by keys.
Also, when I end up querying by properties, I need to create indexes on properties, which I know will be unique