สร้างอินสแตนซ์ของเอนทิตีภายในเอนทิตีเดียวกันใน 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