Создайте экземпляр объекта внутри того же объекта в Google App Engine python ndb

Как создать экземпляры объекта внутри одного объекта. Я хочу:

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

person Gaurav Saini    schedule 24.08.2014    source источник


Ответы (1)


Вы можете динамически обновлять модель после ее создания:

class User(ndb.Model):
  pass

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

_fix_up_properties описание из источников:

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.
    """
person Dmytro Sadovnychyi    schedule 24.08.2014