GAE - How to edit / update data store 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 change the value of the task name? I have task1 and I want to change it to task1-project
source to share
oops sorry, Here's 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"
task.put ()
btw i am getting it now. I changed task = Task () in task = query.get () and it worked.
Thanks for the help, by the way.
source to share
Given an instance t
of Task
(for example from some operation get
on db
), you can make the change you want, for example. t.taskname = t.taskname + '-project'
(if you want to "add '-project'
to what was there before.) After all, you probably also .put
t
need to go back to the repository, of course (but if you make multiple changes you don't need to check it in after every change - only when you're done change!).
source to share