コード例 #1
0
    class Person(models.Base):

        extra = field
        extra_required = fields.DictField(required=True)
        extra_default = fields.DictField(default={
            "extra_default": "Hello",
            "deep_extra": {
                "spanish": "Hola"
            }
        },
                                         validators=[validators.Length(2)])
        extra_nullable = field.DictField(nullable=True)
コード例 #2
0
    class Person(models.Base):

        name = fields.StringField()
        surname = fields.StringField()
        age = fields.IntField()
        cash = fields.FloatField()
        extra_data = fields.DictField()
コード例 #3
0
    class Person(models.Base):

        name = fields.StringField(required=True)
        surname = fields.StringField(required=True)
        age = fields.IntField()
        cash = fields.FloatField()
        extra = fields.DictField()
コード例 #4
0
    class Car(models.Base):
        brand = fields.StringField(required=True)
        registration = fields.StringField(required=True)
        extra = fields.DictField(required=True)

        def __init__(self, some_value):
            pass
コード例 #5
0
def test_dict_field():

    field = fields.DictField()

    class Person(models.Base):

        extra = field
        extra_required = fields.DictField(required=True)
        extra_default = fields.DictField(default={
            "extra_default": "Hello",
            "deep_extra": {
                "spanish": "Hola"
            }
        },
                                         validators=[validators.Length(2)])
        extra_nullable = field.DictField(nullable=True)

    person = Person()
    assert person.is_programmer is None

    person.is_programmer = True
    assert person.is_programmer is True

    person.is_programmer = False
    assert person.is_programmer is False

    assert field.parse_value(True) is True
    assert field.parse_value('something') is True
    assert field.parse_value(object()) is True

    assert field.parse_value(None) is None

    assert field.parse_value(False) is False
    assert field.parse_value(0) is False
    assert field.parse_value('') is False
    assert field.parse_value([]) is False
コード例 #6
0
    class Car(models.Base):

        brand = fields.StringField()
        extra = fields.DictField()
コード例 #7
0
    class Car(models.Base):

        brand = fields.StringField(required=True)
        registration = fields.StringField(required=True)
        extra = fields.DictField(required=True)
コード例 #8
0
    class Person(models.Base):

        name = fields.StringField()
        surname = fields.StringField()
        age = fields.IntField()
        extra = fields.DictField()