pattern for updating a datastore object -


i'm wondering right pattern should update existing datastore object using endpoints-proto-datastore.

for example, given model 1 gdl videos:

class task(endpointsmodel):     detail = ndb.stringproperty(required=true)     owner = ndb.stringproperty() 

imagine we'd update 'detail' of task.

i considered like:

@task.method(name='task.update',              path='task/{id}',              request_fields=('id', 'detail')) def updatetask(self, task):     pass 

however, 'task' presumably contain previously-stored version of object, , i'm not clear on how access 'new' detail variable update object , re-store it.

put way, i'd write this:

def updatetask(self, task_in_datastore, task_from_request):     task_in_datastore.detail = task_from_request.detail     task_in_datastore.put() 

is there pattern in-place updates of objects endpoints-proto-datastore?

thanks!

see documentation details on this

the property id 1 of 5 helper properties provided default perform common operations (retrieving id). in addition there entitykey property provides base64 encoded version of datastore key , can used in similar fashion id...

this means if use default id property current object retrieved , updates request replace on current object. hence doing trivial:

@task.method(name='task.update',              path='task/{id}',              request_fields=('id', 'detail')) def updatetask(self, task):     task.put()     return task 

will perform intended.


Comments

Popular posts from this blog

c# - How to get the current UAC mode -

postgresql - Lazarus + Postgres: incomplete startup packet -