问题
So, I am trying to create an entity with a parent using bulkloader.
I have a Client entity:
class Client(db.Model):
identifier = db.StringProperty()
www_ip = db.StringProperty()
local_ip = db.StringProperty()
status=db.BooleanProperty()
And I want to create a Data entiy as child of Client.
class Data(db.Model):
songscount = db.IntegerProperty()
nextorder = db.IntegerProperty(default=1)
players = db.ListProperty(str)
previousplayer = db.StringProperty()
Client entity exists. Data.yaml is (without preamble):
transformers:
- kind: Data
connector: csv
connector_options:
# TODO: Add connector options here--these are specific to each connector.
property_map:
- property: __key__
external_name: key
import_transform: transform.create_deep_key(('Client', '__key__'), ('Data', transform.CURRENT_PROPERTY))
export_transform: transform.key_id_or_name_as_string
- property: nextorder
external_name: nextorder
import_transform: transform.none_if_empty(int)
- property: players
external_name: players
import_transform: transform.none_if_empty(users.User) # Assumes email address
- property: previousplayer
external_name: previousplayer
import_transform: transform.none_if_empty(users.User) # Assumes email address
- property: songscount
external_name: songscount
import_transform: transform.none_if_empty(int)
I understand that either transform.create_foreign_key or transform.create_deep_key needs to be used. What I dont understand is how to inform about my Client entity (which is parent).
I found one such question discussed How to set parent for datastrore entity during bulkloading data by appcfg.py on Google App Engine? , but 'Code configuration' has been deprecated.
Thanks
回答1:
Old question, but for future reference, it seems the answer is here:
- property: __key__
external_name: key
import_transform: transform.create_deep_key(('clientKey‘, ‘clientKey‘),(’key‘, transform.CURRENT_PROPERTY))
export:
- external_name: clientKey
export_transform: transform.key_id_or_name_as_string_n(0)
- external_name: key
export_transform: transform.key_id_or_name_as_string_n(1)
(adapted from http://longsystemit.com/javablog/?p=23)
来源:https://stackoverflow.com/questions/11223782/uploading-entity-with-parent-using-bulkloader