GoldenBird
GoldenBird

Reputation: 637

Update app engine entity

How to update existing record in app engine.

Upvotes: 4

Views: 6254

Answers (4)

Tadeu Luis
Tadeu Luis

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

Senthil Kumaran
Senthil Kumaran

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

Michal Chruszcz
Michal Chruszcz

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

bgporter
bgporter

Reputation: 36504

Did you read the very good overview here?

  1. Get the record from the datastore by a query of some kind.
  2. Make the changes you need to make
  3. Call put() on the entity or entities that you changed to save them back to the datastore.

Upvotes: 1

Related Questions