shane716 shane716 - 2 months ago 12
Python Question

Google App Engine - updating an entity

I'm using Google App Engine 1.8.3 - Python 2.7 and NDB API as my datastore

Suppose I have a list of group entities displayed on a html table.
And I want to click the name of an individual group to edit the group's information.
What should the key/id of this group be, which one should I use? Please take a look at below

Here's my Model:

class Group(ndb.Model):
name = ndb.StringProperty()
description = ndb.StringProperty()

In my html:

{% for group in groups %}
<a href="/editGroup?id={{ ????????????? }}" {{}} </a>
{{ group.description}}
{% endfor %}

In the ????? inside the
tag, what should I put? what should I pass it back to the server? group.key? or I have to add the Property to Group model as a key property like
groupId = ndb.IntegerProperty()

I'm thinking about using the entity's key, but I couldn't find a way to display the key in the html from 'group', like

I was able to get the numeric id using
, but according to
numeric ids might not be unique.



In NDB, keys have a urlsafe() method which produces a string suitable for use in templates and passing to URLs:

{{ group.key.urlsafe }}

This is documented on the same page you already link to.