Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do get the ID field in App Engine Datastore?

Say I have a blog on Google AppEngine and wants to print out the id of each post through jinja2.

blog = db.GqlQuery('SELECT * FROM Blog')

self.render('blog.html', blog = blog)

and in the template:

{{% for b in blog %}}
{{b.id}}
{{% endfor %}}

Now I havent added an 'id' field to my DB model, I just want to access the build in datastore ID field. How do I do that?

like image 933
Jonas Bolin Avatar asked Dec 26 '22 08:12

Jonas Bolin


1 Answers

Have a look at the db key class. When you have an entity you can do:

entity.key().id_or_name()

or in NDB:

entity.key.id()
like image 78
voscausa Avatar answered Dec 28 '22 23:12

voscausa