How To Model A Contract Database (with Several Buyers Or Sellers) Using Gae Datastore
I'm new to programming and I'm trying to grasp the concept of the GAE datastore. I'm trying to build an app to make it easy write contracts (http://contractpy.appspot.com) and I'd
Solution 1:
Just some thoughts up front. Don't use plurals for your classes. When you fetching an entity it is not a "People" but a Person or Party. You also have your reference properties around the wrong way. As a starting point you could use the following.
class Person(db.Model):
name = db.StringProperty(required = True)
profession = db.StringProperty(required = True)
driverLicense = db.IntegerProperty(required = True)
address = db.PostalAdressProperty(required = True)
class Contract(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)
class ContractingParty(db.Model):
person = db.ReferenceProperty(People, required=True, collection_name="party_to_contracts")
condition = db.StringProperty(required = False, choices=set(["buyer", "seller", "renter", "owner", "witness"]))
Some things to note.
- You don't need idContract in the Contract entity unless you need a settable (externally sourced) contract number. The entities Key will be enough to uniquely identify the contract.
- Create the ContractingParty entities with the Contract as a parent. Then all ContractingParty entities associated with the contract will be children, and in the same entity group.
- Note the collection_name in the person property ContractingParty. This means that given a person object you can then get all ContractingParty records that refer to the person.
<someperson>.party_to_contracts.run()
. Then you can get the contract from the ContractingParty entity by callingparent()
on it. You can still do this without defining collection_name, but in this case it would be called contractingparty_set. - Given a Contract you can fetch all parties with
ContractingParty.all().ancestor(thecontract).run()
Without a full understanding of you application I can't directly recommend a more refined model, but this would work and is based on your what you have tried to do here.
Hope it helps.
Post a Comment for "How To Model A Contract Database (with Several Buyers Or Sellers) Using Gae Datastore"