class Employee(Collection): _allow_extra_fields = True __collection__ = 'employee' _index = [{'type': 'hash', 'unique': False, 'fields': ['name']}] _key = String(required=True) # registration number name = String(required=True, allow_none=False) department_key = String(required=False) role_key = String(required=False) hired_on = Date(default=datetime.now) department = relationship(Department, field='department_key') role = relationship(Role, field='role_key')
class Person(Collection): __collection__ = "persons" _allow_extra_fields = False _index = [{"type": "hash", "unique": False, "fields": ["name"]}] _allow_extra_fields = False # prevent extra properties from saving into DB _key = String() name = String(required=True, allow_none=False) age = Integer(allow_none=True, missing=None) dob = Date(allow_none=True, missing=None) is_staff = Boolean(default=False) cars = relationship(__name__ + ".Car", "_key", target_field="owner_key") @property def is_adult(self): return self.age and self.age >= 18 @lazy_property def lazy_is_adult(self): return self.age and self.age >= 18 def __str__(self): return "<Person(" + self.name + ")>"
class Person(Collection): __collection__ = 'persons' _allow_extra_fields = False _index = [{'type': 'hash', 'unique': False, 'fields': ['name']}] _allow_extra_fields = False # prevent extra properties from saving into DB _key = String(required=True) name = String(required=True, allow_none=False) age = Integer(missing=None) dob = Date() is_staff = Boolean(default=False) cars = relationship(__name__ + ".Car", '_key', target_field='owner_key') @property def is_adult(self): return self.age and self.age >= 18 @lazy_property def lazy_is_adult(self): return self.age and self.age >= 18 def __str__(self): return "<Person(" + self.name + ")>"
class Car(Collection): __collection__ = "cars" _allow_extra_fields = True make = String(required=True) model = String(required=True) year = Integer(required=True) owner_key = String(allow_none=True, missing=None) owner = relationship(Person, "owner_key") def __str__(self): return "<Car({} - {} - {})>".format(self.make, self.model, self.year)
class Car(Collection): __collection__ = 'cars' _allow_extra_fields = True make = String(required=True) model = String(required=True) year = Integer(required=True) owner_key = String() owner = relationship(Person, 'owner_key') def __str__(self): return "<Car({} - {} - {})>".format(self.make, self.model, self.year)
class Person(Collection): class Hobby(Collection): class Equipment(Collection): name = String(required=False, allow_none=True) price = Number(required=False, allow_none=True) name = String(required=False, allow_none=True) type = String(required=True, allow_none=False) equipment = List(Nested(Equipment.schema()), required=False, allow_none=True, default=None) __collection__ = "persons" _allow_extra_fields = False _index = [{"type": "hash", "unique": False, "fields": ["name"]}] _allow_extra_fields = False # prevent extra properties from saving into DB _key = String() name = String(required=True, allow_none=False) age = Integer(allow_none=True, missing=None) dob = Date(allow_none=True, missing=None) is_staff = Boolean(default=False) favorite_hobby = Nested(Hobby.schema(), required=False, allow_none=True, default=None) hobby = List(Nested(Hobby.schema()), required=False, allow_none=True, default=None) cars = relationship(__name__ + ".Car", "_key", target_field="owner_key") @property def is_adult(self): return self.age and self.age >= 18 @lazy_property def lazy_is_adult(self): return self.age and self.age >= 18 def __str__(self): return "<Person(" + self.name + ")>"