Reputation: 637
How to update existing record in app engine.
Upvotes: 4
Views: 6254
Reputation: 111
I use GQL to query a find the Entity and if exists update de atribute.
result = db.GqlQuery('select name from Person where name = "tadeu"')
if result:
for r in result:
r.attribute = "value"
r.put()
Upvotes: 2
Reputation: 56841
Use gql if you have access to the datastore.
You have to define methods to do the update according your db class. The updates can happen only via the class and it needs to be called upon by requests.
Upvotes: -3
Reputation: 2490
As long as an entity has a key defined it will be updated on put()
:
record = Record(value='foo')
# This creates a new record
record.put()
record.value = 'shmoo'
# This updates it
record.put()
key = record.key()
record2 = Record.get(key)
record2.value = 'bar'
# Yet again this updates the same record
record2.put()
Upvotes: 41