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)
class Person(models.Base): name = fields.StringField() surname = fields.StringField() age = fields.IntField() cash = fields.FloatField() extra_data = fields.DictField()
class Person(models.Base): name = fields.StringField(required=True) surname = fields.StringField(required=True) age = fields.IntField() cash = fields.FloatField() extra = fields.DictField()
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
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
class Car(models.Base): brand = fields.StringField() extra = fields.DictField()
class Car(models.Base): brand = fields.StringField(required=True) registration = fields.StringField(required=True) extra = fields.DictField(required=True)
class Person(models.Base): name = fields.StringField() surname = fields.StringField() age = fields.IntField() extra = fields.DictField()