[英]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.