我是编程新手,我正在尝试掌握 GAE 数据存储的概念。我正在尝试构建一个应用程序以简化编写合同(http://contractpy.appspot.com),我想知道:如何为数据库建模以记录合同(考虑到合同可以有几个人在交易的同一侧)?
在关系模型中,我将执行以下操作:为人员创建一个表,然后为合同创建一个表,并参考参与该合同的人员创建第三个表。看起来像这样(我猜):
CREATE TABLE people(
id INTEGER(8) NOT NULL AUTO_INCREMENT PRIMARY KEY,
name VARCHAR(250) NOT NULL,
profession VARCHAR(30),
driverLicense VARCHAR(12),
address VACHAR(60)
)ENGINE=InnoDB CHARACTER SET utf8 COLLATE utf8_general_ci;
CREATE TABLE contracts(
idContract INTEGER(7) NOT NULL AUTO_INCREMENT PRIMARY KEY,
contractType VACHAR(12), # purchase contract, rental contract etc.
contractDate DATE,
place VACHAR(12),
)ENGINE=InnoDB CHARACTER SET utf8 COLLATE utf8_general_ci;
CREATE TABLE contractingParties(
FK_id INTEGER(7) NOT NULL FOREIGN KEY(FK_id) references people(id),
FK_idContract INTEGER(7) NOT NULL FOREIGN KEY(FK_idContract) references contracts(idContract),
condition VACHAR(12), # e.g., buyer, seller, renter, owner etc.
)ENGINE=InnoDB CHARACTER SET utf8 COLLATE utf8_general_ci;
我的问题是:在 GAE 数据存储中执行此操作的最佳方法是什么?我在下面画了一个草图,但我不确定这是使用 GAE 数据存储非关系概念的正确思维方式。
我在 Python 2.7 中使用 GAE。
提前感谢您的任何帮助/建议!
class People(db.Model):
name = db.StringProperty(required = True)
profession = db.StringProperty(required = True)
driverLicense = db.IntegerProperty(required = True)
address = db.PostalAdressProperty(required = True)
class Contracts(db.Model):
idContract = db.IntegerProperty(required = True)
contractType = db.StringProperty(required = True, choices=set(["Purchase Agreement", "Rental House", "Rental Car"]))
contractDate = db.DateProperty (required = True, auto_now = True, auto_now_add = True)
place = db.StringProperty(required = True)
parties = db.ReferenceProperty(ContractingParties, required = True)
class ContractingParties(db.Model):
person = db.ReferenceProperty(People, required=True)
contract = db.ReferenceProperty(Contracts, required=True)
condition = db.StringProperty(required = False, choices=set(["buyer", "seller", "renter", "owner", "witness"]))