简体   繁体   English

Google App Engine数据存储模型参考另一类

[英]Google App Engine Data Store Model Reference Another Class

So that you can understand the data model, I basically have cities and within each one I'll have categories and then inside each category I'll have listings. 为了使您能够理解数据模型,我基本上有城市,在每个城市中都有类别,然后在每个类别中都有清单。 Here's what I have so far. 到目前为止,这就是我所拥有的。

from google.appengine.ext import db

class City(db.Model):
    name = db.StringProperty(required=True)
    connections = db.ListProperty()
    categories = db.ListProperty()

So Next, I want to add: 因此,接下来,我要添加:

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

But do I need to specify that only Category should be in categories or something to that effect? 但是我是否需要指定只有类别才属于类别或某种意义上的东西?

You want to look at a custom property named KeyListProperty in App Engine Patch . 您要查看App Engine Patch中名为KeyListProperty的自定义属性。 That will give you the sort of many-to-many relationship you want. 这将为您提供所需的多对多关系。

You need to throw the categories property from your City and use a ReferenceProperty in your Category class: 您需要从您的City抛出categories属性,并在Category类中使用ReferenceProperty

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

This will also automatically add categories collection for your City model. 这还将自动为您的City模型添加categories集合。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Google App Engine上的反向指数数据存储 - Inverted Indices Data Store on Google App Engine Google App Engine项目/交易数据模型 - Google app engine item / transaction data model Google App Engine:如何在db.Model类中将默认值从一个属性设置为另一个属性? - Google App Engine: How to Set Default Value from a property to another property in db.Model Class? 启动时使用Google App Engine在Google数据存储区中自动填充初始数据 - Google App Engine on startup autofill initial data in google data store Google App Engine数据库模型静态(类)变量 - Google app engine db model static ( class ) variables 使用python的Google App Engine中的多个ndb.model类 - multiple ndb.model class in google app engine with python 在python中为谷歌应用引擎创建枚举模型类的最佳方法? - Best way to create an enum model class for google app engine in python? Google App Engine:为具有SQL背景的人员介绍他们的Data Store API? - Google App Engine: Intro to their Data Store API for people with SQL Background? 如何在Google App Engine上存储HTML 5地理位置数据? - How do I store HTML 5 Geolocation Data on Google App Engine? 在Google App Engine中同步删除数据存储条目 - Delete Data store entries synchronously in Google App Engine
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM