In datastore, confused on how to pass a list of key_names as an argument to somemodel.get_or_insert(

Posted by indiehacker on Stack Overflow See other posts from Stack Overflow or by indiehacker
Published on 2010-04-01T07:46:43Z Indexed on 2010/04/01 9:23 UTC
Read the original article Hit count: 254

Are there examples of how to pass a list of key_names to Model.get_or_insert() ?

My Problem:

With a method of ParentLayer I want to make the children.

The key_names of the new (or editable) entities of class Child will come from such a list below:

namesList = ["picture1","picture2"]

so I should be able to build a list of key_names with method from the parent class as follows:

class ParentLayer(db.Model):

    def getOrMakeChildren(self, namesList):
            keyslist = [ db.Key.from_path( 'Child' , name , parent = self.key() ) for name in namesList ]

the problem is next where I simply want to get_or_insert entities based on keylist defined above:

            childrenEntitiesList = Child.get_or_insert(keyslist) # no works?

also none of the below attempts worked:

            #childrenEntitiesList = Child.get_or_insert(keyslist, parent = u'TEST') 
            #childrenEntitiesList = Child.get_or_insert(keyslist, parent=self.key().name() ) 
            #childrenEntitiesList = Child.get_or_insert(keyslist, parent=self.key() 

© Stack Overflow or respective owner

Related posts about google-app-engine

Related posts about google-datastore