Gaurav Saini
Gaurav Saini

Reputation: 77

Create an instance of an entity within same entity in Google App Engine python ndb

How do i create instances of an entity within the same entity. What i want is :

class User(ndb.model):
    friends = ndb.StructuredProperty( User, repeated=True )

Upvotes: 0

Views: 75

Answers (1)

Dmytro Sadovnychyi
Dmytro Sadovnychyi

Reputation: 6201

You can update model dynamically after it was created:

class User(ndb.Model):
  pass

User.friends = ndb.StructuredProperty(User, repeated=True)
User._fix_up_properties()

_fix_up_properties description from the sources:

def _fix_up_properties(cls):
    """Fix up the properties by calling their _fix_up() method.
    Note: This is called by MetaModel, but may also be called manually
    after dynamically updating a model class.
    """

Upvotes: 1

Related Questions