class MyListField(ListField):
def __init__(self, max_length=None, **kwargs):
self.max_length = max_length
super(MyListField, self).__init__(**kwargs)
def validate(self, value):
super(MyListField, self).validate(value)
if self.max_length is not None and len(value) > self.max_length:
self.error('Too many items in the list')
在
ListField
中没有这样的内置功能,但是您可以让您的自定义ListField
提供一个max_length
属性:相关问题 更多 >
编程相关推荐