代码之家  ›  专栏  ›  技术社区  ›  Noah Clark

Google App Engine数据存储模型引用另一个类

  •  0
  • Noah Clark  · 技术社区  · 14 年前

    为了让您了解数据模型,我基本上有城市,在每个城市中,我有类别,然后在每个类别中,我有列表。这是我目前所拥有的。

    from google.appengine.ext import db
    
    class City(db.Model):
        name = db.StringProperty(required=True)
        connections = db.ListProperty()
        categories = db.ListProperty()
    

    class Category(db.Model)
        name = db.StringProperty(required=True)
    

    但我是否需要指定只有类别应该在类别中,或是类似的?

    2 回复  |  直到 14 年前
        1
  •  0
  •   Xion    14 年前

    你需要把 categories 您的财产 City 并使用 ReferenceProperty 在你的 Category

    class Category(db.Model)
        name = db.StringProperty(required=True)
        city = db.ReferenceProperty(City, collection_name = 'categories')
    

    这也将自动添加 类别 西蒂 模型。

        2
  •  1
  •   mrbillyocean    14 年前

    App Engine Patch . 这会给你想要的那种多对多的关系。