GAE DataStore: query a existing by user_id field
-
07-06-2021 - |
Pergunta
I have saved the user_id() field and now I want to query the datastore for that user. How would I go about accomplishing that?
#Something like
user = db.Query(MyUser).filter('user.user_id() = ', 1234).fetch(limit=1)
Thanks
Solução
You should create a separate string property to store the user ID, then query for that. The UserProperty class is full of traps and is best avoided.
Outras dicas
if what you are searching for is the actual entity Id then you can query for it with the get_by_id
method
user = MyUser.get_by_id(1234)
note that if you create it with a parent the you need to pass that to the get_by_id()
function too.
user = MyUser.get_by_id(1234, parent=parent)
docs: https://developers.google.com/appengine/docs/python/datastore/modelclass#Model_get_by_id
Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow