示例#1
0
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 + ")>"
示例#2
0
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 + ")>"
示例#3
0
class User(Collection):

    __collection__ = 'user'
    _index = [{'type': 'hash', 'unique': False, 'fields': ['username']}]
    # _key = String(required=True)

    # firstname = String(required=True, allow_none=True)
    # lastname = String(required=True, allow_none=True)
    username = String(required=True, allow_none=False)
    password = String(required=True, allow_none=False)
    email = String(required=True, allow_none=False)
    is_active = Boolean(required=True, default=False, allow_none=False)
    is_superuser = Boolean(required=True, default=False, allow_none=False)
    dob = Date(required=True, allow_none=True)
    # createdate = DateTime(required=True, allow_none=False)

    @property
    def key(self):
        return self._key
示例#4
0
class Subject(Collection):
    __collection__ = "subjects"

    _key = String(required=True)  # subject code
    name = String(required=True)
    credit_hours = Integer(allow_none=True, missing=None)
    has_labs = Boolean(missing=True)

    def __str__(self):
        return "<Subject({})>".format(self.name)
示例#5
0
        class MyModel(Collection):
            __collection__ = "MyCollection"

            _key = String(allow_none=True)
            integer = Integer(allow_none=True)
            datetime = DateTime(allow_none=True)
            url = Url(allow_none=True)
            bool_val = Boolean(allow_none=True)
            str_list = List(String, allow_none=True)
            floater = Float(allow_none=True)
            date = Date(allow_none=True)
            timedelta = TimeDelta(allow_none=True)
            email = Email(allow_none=True)
            number = Number(allow_none=True)
            uuid = UUID(allow_none=True)
            d = Dict(allow_none=True)
示例#6
0
        class MyModel(Collection):
            __collection__ = "MyCollection"

            _key = String()
            integer = Integer()
            datetime = DateTime()
            url = Url()
            bool_val = Boolean()
            str_list = List(String)
            floater = Float()
            date = Date()
            timedelta = TimeDelta()
            email = Email()
            number = Number()
            uuid = UUID()
            d = Dict()
示例#7
0
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 + ")>"
示例#8
0
 class _Schema(Schema):
     _key = String(required=True)  # subject code
     name = String(required=True)
     credit_hours = Integer()
     has_labs = Boolean(missing=True)