Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

print the appengine model entity id in the html template

Following is the simple database model i have:

class Notes(db.Model):
  text = db.StringProperty(multiline=True)
  date = db.DateTimeProperty(auto_now_add=True)

Now in the url handler, i send all the notes to the template as follows:

class MainPage(webapp2.RequestHandler):
  def get(self):
    notes = Notes.all()
    self.render_template("index.html", {'notes':notes})

In the template i am using jinja2 templating engine, i want the id of each of the notes to be printed, so that i can embed an edit link, somewhat like this:

{% for note in notes %}
<p>  
 {{ note.text }} <br>
 {{ note.date }} <br>
 (<a href ="edit/{{note.key.id}}">edit </a>)
{% endfor %}

But the trouble is, i dont see anything printed, in place of note.key.id As per the docs over here key class represents a unique key for a database entity and this has a method id, its a numeric value. for a single note from the collection of notes i want the id of the note.

If i use the django templating engine i get the values {{ notes.key.id }} printed, but with jinja2 i dont see it.

How can i do this?

like image 918
user993563 Avatar asked Apr 26 '12 19:04

user993563


1 Answers

Well replace the href line with the following:

(<a href ="edit/{{note.key().id()}}">edit </a>)

This shall be enough.

like image 139
apcelent Avatar answered Sep 29 '22 14:09

apcelent