Esempio n. 1
0
class Dummy(BaseModel):
    id = Field(int, primary_key=True, length=11, auto_increment=True)
    name = Field(str, noneable=True, default='dummy', length=255,
                 charset='utf8mb4')
    age = Field(int, default=12, on_update=lambda x: x.__class__.age + 1,
                length=11)
    password = Field(str, noneable=True, encrypt=True, length=511)
    flag = Field(int, noneable=True, choices=[0, 1, 2], length=5)
    tags = Field([str], default=[])
    payload = Field({str: [int]}, noneable=True, default={})
    foo = Field(int, noneable=True, length=11)
    dynasty = Field(str, default='现代', length=4)
    dynasty1 = Field(str, noneable=True, length=4)
    created_at = Field(
        datetime,
        default=datetime.now
    )
    updated_at = Field(
        datetime,
        default=datetime.now,
        on_update=datetime.now
    )
    created_date = Field(
        date,
        default=date.today
    )
    prop1 = DbField([str], noneable=True)
    count = DbField(int, default=0, choices=range(30),
                    on_update=lambda x: x.count + 3)
    db_dt = DbField(datetime, noneable=True)
    count1 = DbField(int, noneable=True)

    def get_uuid(self):
        return '/dummy/{}'.format(self.id)

    def after_update(self):
        after_update()

    def before_update(self, **attrs):
        before_update()

    @classmethod
    def before_create(cls, **attrs):
        before_create()

    @classmethod
    def after_create(cls, inst):
        after_create()
Esempio n. 2
0
File: base.py Progetto: yetone/olo
class Foo(BaseModel):
    id = Field(int, primary_key=True, auto_increment=True, length=11)
    name = Field(str, noneable=True, default='foo', length=255)
    age = Field(int, noneable=True, default=1, length=11)
    age_str = Field(int, noneable=True, default=1, output=str, length=11)
    key = Field(str, noneable=True, default=lambda: str(uuid4()), length=255)
    prop1 = DbField(list, noneable=True)
    boolean = Field(bool, default=False)
    test_getter = Field(int, default=0)
    test_setter = Field(int, default=0)

    @test_getter.getter
    def test_getter(self, value):
        return value + 1

    @test_setter.setter
    def test_setter(self, value):
        return value - 1

    __unique_keys__ = ((name, 'age'), ('key', ))

    __index_keys__ = ('age', )

    def get_uuid(self):
        return '/foo/{}'.format(self.id)
Esempio n. 3
0
        class Test(BaseModel):
            name = DbField(str)

            @override
            def __init__(self, id):
                super(Test, self).__init__(_olo_is_new=False)
                self.id = id

            @override
            def _clone(self):
                return self.__class__(self.id)

            def get_uuid(self):
                return '/tests/test_db_field_model/Test/%s' % self.id
Esempio n. 4
0
File: base.py Progetto: onesafe/olo
class Foo(BaseModel):
    id = Field(int, primary_key=True, auto_increment=True, length=11)
    name = Field(str, noneable=True, default='foo', length=255)
    age = Field(int, noneable=True, default=1, length=11)
    age_str = Field(int, noneable=True, default=1, output=str, length=11)
    key = Field(str, noneable=True, default=lambda: str(uuid4()), length=255)
    prop1 = DbField(list, noneable=True)

    __unique_keys__ = (('name', 'age'), ('key', ))

    __index_keys__ = ('age', )

    def get_uuid(self):
        return '/foo/{}'.format(self.id)
Esempio n. 5
0
        class Test__(BaseModel):
            name = DbField(str)

            @override
            def __init__(self, id, name='test'):
                super(Test__, self).__init__()
                self.id = id
                if not self.name:
                    self.name = name
                    self.save()

            @override
            def _clone(self):
                return self.__class__(self.id)

            def get_uuid(self):
                return '/tests/test_db_field_model/Test__/%s' % self.id
Esempio n. 6
0
File: base.py Progetto: onesafe/olo
class Bar(BaseModel):
    name = Field(str, primary_key=True, length=255)
    age = Field(int, default=1, length=11)
    xixi = Field(str, name='key', default=lambda: str(uuid4()), length=255)
    word = Field(str, noneable=True, length=255)
    prop1 = DbField(list, noneable=True)

    __index_keys__ = ((), ('xixi', 'age'), 'age')

    __order_bys__ = (
        'xixi',
        ('xixi', 'age'),
        ('-age', 'xixi'),
    )

    def get_uuid(self):
        return '/foo/{}'.format(self.id)
Esempio n. 7
0
 def new_age(cls):
     return DbField(int)