mFontoura
mFontoura

Reputation: 257

Referring to an entity from another page

I'm using Google App Engine for creating a page with a form to create an entity called "tutorial". Then when hit next, the user has another form in order to create a chapter for the tutorial previously created. My problem is bringing the reference of the "tutorial" to the "chapter"

handler for the new tutorial page:

class NewTut(FuHandler):
    def get(self):
        self.render('newTut.html')
    def post(self):
        title = self.request.get("title")
        tags = self.request.get("tags")
        tut = Tutorial(title=title, tags=tags)
        tut.put()

        self.redirect('/newchap' #should i put here 'tut'?#)

This part works perfectly but then how do I use this tut when creating a chapter?

handler for the new chapter page:

class NewChap(FuHandler):
    def get(self):
        self.render('newChapter.html')

    def post(self):
        tutorial = Tutorial(??????)
        title = self.request.get("chapTitle")
        content = self.request.get("content")
        note = self.request.get("note")

What do I need to do here to get this referencing working?

Upvotes: 1

Views: 105

Answers (3)

dlorenc
dlorenc

Reputation: 531

You want to pass the tutorial id to the next page through the URL. You could do this as a get parameter, or just part of the path. Here's how to do it as a get parameter:

self.redirect('/newchap?tutorial_id=%s' % tut.key)

Then, in your NewChap handler:

tutorial_id = request.get("tutorial_id")
tutorial = db.Key.from_path('Tutorial', tutID)

Upvotes: 2

mFontoura
mFontoura

Reputation: 257

Part of @dlorenc answer works, because on the NewChap it doesn't work. So this is how i got it working:

in NewTut hadler:

self.redirect('/newchap?tutorial_id=%s' % tut.key)

and in the NewChap handler, on the post:

tutID = self.request.get("tutorial_id")
tutorial = db.Key.from_path('Tutorial', tutID)

Upvotes: 1

maddyblue
maddyblue

Reputation: 16882

You should redirect to '/newchap/%s' %tut.key.id() and then fetch the id out in the request.

Upvotes: 0

Related Questions