Reputation: 1833
as a new Python programmer, I am struggling with a really simple problem.
I want to get a record by id, update it and save it back to datastore.
I am holding the id that was generated by appstore in a hidden field in the form, but I can't figure how to query for one record with id !
Upvotes: 1
Views: 271
Reputation: 13096
That should be easy, using Model.get_by_id() and instance.put():
instance = Model.get_by_id(id) # get the object instance by id
instance.name = "new name" # modifies the instance
instance.put() # creates if new object, updates otherwise
Upvotes: 3
Reputation: 5842
Guess you are using django - nonrel else @ShadowCloud solution should work. If so
pk = request.GET.get('hiddenfieldname').
instance = Model.objects.get(pk)
instance.name = 'new name'
instance.save()
if you are using django-nonrel which means you are running a django project compatible to appengine. In that everything goes django ways. If you go through django docs. you will get everything. Else if you are just using the django templates. everything goes webapp ways. webapp is the default framework.
Upvotes: 2