1
votes

I want to download my App Engine data so I can operate on it efficiently locally (I'm generating some PDFs based on it). How can I define that the column for a ReferenceProperty gets populated by a particular property of the referenced model rather than just the key or id?

Here are my model classes:

class Department(db.Model):
   name = db.StringProperty()

class User(db.Model):
   userKey = db.StringProperty(required=True)
   secret = db.StringProperty()
   dept = db.ReferenceProperty(Department, required=True)

However, even though I have described a property_map in bulkloader.yaml like so:

- kind: User
  connector: csv
  connector_options:
  property_map:
    - property: __key__
      external_name: key
      export_transform: transform.key_id_or_name_as_string

    - property: dept
      external_name: dept
      import_transform: transform.create_foreign_key('Department')
      export_transform: transform.key_id_or_name_as_string

    - property: secret
      external_name: secret

    - property: userKey
      external_name: userKey

I always end up with the Department key in the CSV

e.g.

   dept     secret    key
1184017  mySecret  myKey

How can I define that the dept column gets populated by the 'name' property of the Department model?

e.g.

   dept     secret    key
myDept  mySecret  myKey

thanks, paul

1

1 Answers

1
votes

Create a file uploadutil.py and add this method in it:

def prop_converter(dept):
  # load the department then return the property you want
  return dept.name

Then add this in bulkloader.yaml:

Add import for uploadutil:

import: uploadutil

And add property:

- property: dept
    external_name: dept
    import_transform: transform.create_foreign_key('Department')
    export_transform: uploadutil.prop_converter

hence the above method is called on export!