Tutorial :GAE - How Do i edit / update the datastore in python


I have this datastore model

class Project(db.Model)  projectname = db.StringProperty()  projecturl = db.StringProperty()    class Task(db.Model)  project = db.ReferenceProperty(Project)  taskname= db.StringProperty()  taskdesc = db.StringProperty()  

How do I edit the value of taskname ? say I have task1 and i want to change it to task1-project


oops sorry, Here is the formatted code:

taskkey = self.request.get("taskkey")
taskid = Task.get(taskkey)
query = db.GqlQuery("SELECt * FROM Task WHERE key =:taskid", taskid=taskid)

if query.count() > 0:
task = Task()
task.taskname = "task1-project"

by the way I get it now. I changed the task=Task() into task = query.get() and it worked.

Thanks for helping by the way.


Given an instance t of Task (e.g. from some get operation on the db) you can perform the alteration you want e.g. by t.taskname = t.taskname + '-project' (if what you want is to "append '-project' to whatever was there before). Eventually, you also probably need to .put t back into the store, of course (but if you make multiple changes you don't need to put it back after each and every change -- only when you're done changing it!-).


Probably the easiest way is to use the admin console. Locally it's:


and if you've uploaded it, it's the dashboard:


Here's a link:

Note:If u also have question or solution just comment us below or mail us on toontricks1994@gmail.com
Next Post »