user1322731
user1322731

Reputation: 71

How to modify entry in database in appengine?

Want to edit datatabase. I have tried this, but it doesn't work.

    def post(self, pageName):$
        content = self.request.get('content')$
$
        p = db.GqlQuery("SELECT * FROM Pages")$
        pages = p.run(batch_size = 1000)$
        pageExist = False$
$
        for page in pages:$
            if pageName == page.name:$
                page.content = content$
                break$
            else:$
                p = Pages(name = pageName, content = content)$
                p.put()$
        self.redirect(pageName)$

Need some code help.

Upvotes: 0

Views: 97

Answers (1)

Dave W. Smith
Dave W. Smith

Reputation: 24966

When you find pageName and change the content on the corresponding page, you'll need to save page before redirecting.

And if the intent is to update a page with new content, I'm not at all sure what you're trying to accomplish with that else: block.

I think you'll be happier doing something like

query = db.GqlQuery("SELECT * FROM Pages WHERE pageName=:1", pageName)
for page in query:
  page.content = content
  page.put()

Upvotes: 2

Related Questions