1

我有以下关系模式(比如 MySQL,它真的在我的脑海中):

Login, Customer, Friendship, Address, Child, School

这样

Login(username, password)
Customer(id, firstName, lastName)
Friendship(customer_id, customer_id) //many to many
Address(customer_id, street, city, state, zip)
Child(id, firstName, lastName, customer_id, school_id)//each customer may have many children
School(id, name, city, state, zip)// there are many children per school

我想将架构重写为 Google App Engine 高复制数据存储 (HRD) 架构:有人知道该怎么做吗?

据我所知,这是:

class Login(db.Model):
 username = db.StringProperty()
 password = db.StringProperty()

class Customer(db.Model):
 first_name = db.StringProperty()
 last_name = db.StringProperty()

class Address(db.Model):
 # what goes here?

class Friendship(db.Model):
 # what goes here?

class Child(db.Model):
 # what goes here?

class School(db.Model):
 # what goes here?

我正在使用python 2.7。

4

1 回答 1

1

首先,我建议使用ndb而不是db. 查看文档以获取更多信息。

您似乎掌握了一些标准字符串属性,这主要是您所需要的。

对于引用其他模型的模型,您可以使用KeyProperty例如

from google.appengine.ext import ndb

class Friendship(ndb.Model):
  first_friend = ndb.KeyProperty(kind=Friend)
  second_friend = ndb.KeyProperty(kind=Friend)
于 2012-11-22T19:13:11.600 回答