0

I'm trying to make a query comparing a key but i don't get any results.

I have a Tutorial and a Chapter Model. The chapter Model contais a keyProperty of kind Tutorial. ( tutKey = ndb.KeyProperty(kind='Tutorial'))

tutID = self.request.cookies.get('tut_id', '')

tutIns = ndb.Key('Tutorial', int(tutID)).get()
chaps = Chapter.query(Chapter.tutKey == tutIns.key)

self.render('editTut.html', chaps=chaps, tutins=tutIns.key)

I'm sending tutIns.key just to test if the instance is working, and yes it returns the Key(Key('Tutorial', 1)). Also if i make just the query Chapter.query() it returns all the chapters as expected.

And this is how I am storing the tutkey on the chapter:

tutID = self.request.cookies.get('tut_id', '')
tutorial = ndb.Key('Tutorial', tutID)
.
.
.

chap = Chapter(tutKey=tutorial, title=title, content=content,
                           note=note, order=order)
chap.put()

In the Development Console i can see that the tutkey stored in the chapter1 and chapter2 are the same key, but that key is not equal to the tutorial key. I'm i creating the chapter in a wrong way?

mFontoura
  • 257
  • 2
  • 15

1 Answers1

3

Here, you are converting the ID to an int:

tutIns = ndb.Key('Tutorial', int(tutID)).get()

But here, you are using it as a string:

tutID = self.request.cookies.get('tut_id', '')
tutorial = ndb.Key('Tutorial', tutID)

The resulting Key instances aren't equal.

Greg
  • 10,350
  • 1
  • 26
  • 35