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

+2


source to share


3 answers


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.

+2


source


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!).



+1


source


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

http://localhost:8080/_ah/admin

      

and if you downloaded it, this is the toolbar:

http://appengine.google.com/dashboard?&app_id=******

      

Here is the link :

-1


source







All Articles