Altering data in GQL
I need to change values for an entry, but the following code doesn't work.
logList = db.GqlQuery("SELECT * FROM Log ORDER BY date DESC LIMIT 1")
logList[0].content = "some text"
db.put(logList)
The value for the newest element doesn't change when I run this. I checked the output with Print, it gives correct value (to what the content field开发者_运维问答 should be changed & the correct old value) and gives the following status code:
Status: 302 Moved Temporarily
Content-Type: text/html; charset=utf-8
Cache-Control: no-cache
Location: http://localhost:8080/admin/editl
Expires: Fri, 01 Jan 1990 00:00:00 GMT
Content-Length: 0
What is wrong with my code? The used method of altering data was mentioned in the official docs.
logList = db.GqlQuery("SELECT * FROM Log ORDER BY date DESC LIMIT 1")
result = logList.get()
result.content = "some text"
result.put()
Try this. You are confusing the GqlQuery object for the results of actually eexecuting the query.
精彩评论