user2764108
user2764108

Reputation: 146

ndb python appengine odd behavior models referencing each other

In referencing models with KeyProperty it seems one has to initialize the model before its referenced Have I missed some bit of information here?

from google.appengine.ext import ndb

#initialize here
class Vessel(ndb.Model):
    pass

class Manifest(ndb.Model):
    vessellist = ndb.KeyProperty(Vessel)

class Vessel(ndb.Model):
    manifest = ndb.KeyProperty(Manifest) 

Upvotes: 0

Views: 56

Answers (1)

dlebech
dlebech

Reputation: 1839

This is normal behavior. If you want to avoid putting your models in a specific order and you want cross references like that, you can reference a model with a string instead of the model class:

class Manifest(ndb.Model):
    vessellist = ndb.KeyProperty('Vessel')

class Vessel(ndb.Model):
    manifest = ndb.KeyProperty('Manifest')

Upvotes: 3

Related Questions