views:

236

answers:

3

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

+1  A: 

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

Alex Martelli
Hi! Thanks for your answer. I use this code but still nothing happens. 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()
gene
Your code is unformatted (edit your answer to show nicely formatted code) but what you're obviously doing is generating a completely new and unrelated task object (with a completely new and unrelated key, of course) and putting it -- that will most obviously not in any way alter the original one, but your assertion that "nothing happens" is grievously wrong (check on your dashboard!!!), you now have one more entity of the Task kind (exactly as you specified). Why aren't you altering your original one as I said but making an entirely new one instead?!?!?
Alex Martelli
A: 

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

http://localhost:8080/_ah/admin

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

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

Here's a link:

Dominic Bou-Samra
+1  A: 

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"
task.put()

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.

gene