Copy an entity in Google App Engine datastore in Python without knowing property names at 'compile' time

后端 未结 7 910
庸人自扰
庸人自扰 2020-11-30 01:25

In a Python Google App Engine app I\'m writing, I have an entity stored in the datastore that I need to retrieve, make an exact copy of it (with the exception of the key), a

7条回答
  •  醉话见心
    2020-11-30 01:44

    I'm neither Python nor AppEngine guru, but couldn't one dynamically get/set the properties?

    props = {}
    for p in Thing.properties():
        props[p] = getattr(old_thing, p)
    new_thing = Thing(**props).put()
    

提交回复
热议问题