def _duplicate(self, source_entity): """ create an instance of source_entity kind, initialize values same as source_entity if source_entity contains key, predict the key of the entity that will be/has already been created """ namespace_manager.set_namespace(self.new_ns) source_id = source_entity.key().id() source_kind = source_entity.key().kind() dest_entity_key = db.Key.from_path(source_kind, source_id) model = getattr(models, source_kind) dest_entity = model(key=dest_entity_key) for attr, value in source_entity._entity.iteritems(): if type(value) == db.Key: new_key = db.Key.from_path(value.kind(), value.key().id()) setattr(dest_entity, attr, new_key) else: setattr(dest_entity, attr, value)
Run
Reset
Share
Import
Link
Embed
Language▼
English
中文
Python Fiddle
Python Cloud IDE
Follow @python_fiddle
Browser Version Not Supported
Due to Python Fiddle's reliance on advanced JavaScript techniques, older browsers might have problems running it correctly. Please download the latest version of your favourite browser.
Chrome 10+
Firefox 4+
Safari 5+
IE 10+
Let me try anyway!
url:
Go
Python Snippet
Stackoverflow Question