I am trying to create something like a folder structure for saving to GAE ndb datastore. I will be saving a top root folder (MjlistitemFolder) to the datastore. A MjlistitemFolder can have a number of other subitems (Mjlistitem) in its items property. Ultimately the content of a folder items will be one of these: MjlistitemFolder, MjlistitemJobGeneric, MjlistitemJobApp
This all works if I create this structure in memory. But after put()ing it away and reloading the root folder from the datastore, I don't get the same structure back.
class Mjlistitem(ndb.Model):
pass
class MjlistitemFolder(Mjlistitem):
title = ndb.StringProperty()
items = ndb.StructuredProperty(Mjlistitem, repeated=True)
class MjlistitemJob(Mjlistitem):
pass
class MjlistitemJobGeneric(MjlistitemJob):
jobtype = ndb.IntegerProperty()
class MjlistitemJobApp(MjlistitemJob):
appleid = ndb.StringProperty()
I get these warnings:
WARNING 2014-04-04 07:14:17,506 model.py:2359] Skipping unknown structured subproperty (items.items.appleid) in repeated structured property (items of MjlistitemFolder)
WARNING 2014-04-04 07:14:17,506 model.py:2359] Skipping unknown structured subproperty (items.items.jobtype) in repeated structured property (items of MjlistitemFolder)
WARNING 2014-04-04 07:14:17,506 model.py:2359] Skipping unknown structured subproperty (items.items.appleid) in repeated structured property (items of MjlistitemFolder)
It seems like the db→instance process renders the stuff in items to be of Mjlistitem class only. How do I make them appear as their real inherited classes?
This is how I create a test structure:
rootfolder = MjlistitemFolder(title="root")
subfolder = MjlistitemFolder(title="Cool things")
subfolder.items.append(MjlistitemJobApp(appleid="281796108")) # evernote
subfolder.items.append(MjlistitemJobGeneric(jobtype=3)) # phone number
subfolder.items.append(MjlistitemJobApp(appleid="327630330")) # dropbox
rootfolder.items.append(MjlistitemJobGeneric(jobtype=15)) # passbook
rootfolder.items.append(subfolder)
rootfolder.items.append(MjlistitemJobGeneric(jobtype=17)) # appstore
rootfolder.put()