GQL get ID field

In google appengine you can get the hash key value by running a query like

select __key__ from furniture

But the appengine datastore supports a beautifully auto-incrementing field identifier for each view.

How can I access it from a request?

select ID from furniture

Does not work

+3
source share
3 answers

I believe that a Gcl request cannot include access method calls or attribute retrieval (in the same spirit as the fact that it can only do "SELECT * FROM"to retrieve whole objects or "SELECT __key__ FROM"to retrieve only keys), it cannot select and select fields, as in [hypothetical! -)] "SELECT this, that FROM").

, , .id() accessor ( None , , , .id_or_name(), , , None ). , , None:

thekeys = db.GqlQuery('SELECT __key__ FROM Whatever').fetch(1000)
theids = [k.id() for k in thekeys if k.id() is not None]
+4

entity.key().id()
+5

I'm not sure if he was there when you asked this question, but now it's pretty easy to get the object by id.

YourModel.get_by_id (int(ids))

You can read more about this in the documentation: https://developers.google.com/appengine/docs/python/datastore/modelclass#Model_get_by_id

0
source

Source: https://habr.com/ru/post/1717524/


All Articles