0
我是新手編程,我試圖掌握GAE數據存儲的概念。我正在嘗試構建一個應用程序來簡化寫合同(http://contractpy.appspot.com),並且我想知道:如何建模數據庫以記錄合同(考慮合同可以有幾個幾個交易的同一方)?如何使用GAE數據存儲建模合同數據庫(與多個買家或賣家)
在關係模型中,我將執行以下操作:爲人員創建表格,然後爲合同創建表格,併爲參與合同的人員創建第三個表格。會是這個樣子(我猜):
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數據存儲非關係概念的正確思路。
我使用GAE與Python 2.7。
在此先感謝您的任何幫助/建議!
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"]))
謝謝@Tim霍夫曼,你的建議幫了我很多! – craftApprentice