Validating List of DictType
bencarter78 opened this issue · 1 comments
bencarter78 commented
python = 3.7.0
version = '2.1.0'
Hello
I'm getting an error when trying to validate of list of dicts.
class LearningAims(Model):
aims = ListType(DictType(StringType), required=True)
data = [{"name": "foo"}, {"name": "bar"}]
LearningAims(data).validate()
The error is TypeError: list indices must be integers or slices, not dict
What am I doing wrong?
tirkarthi commented
I guess you should be passing data as a dictionary with field name and value.
from schematics.models import Model
from schematics.types import StringType, ListType, DictType
class LearningAims(Model):
aims = ListType(DictType(StringType), required=True)
data = {"aims": [{"name": "foo"}, {"name": "bar"}]}
LearningAims(data).validate()