Closed Rustem closed 11 years ago
Hi Rustem!
I think you're wrong with your issue because Booby does not have a ListField yet (maybe you have used another fork of this repo). Anyway we're working on a ListField implementation and your comment is very useful for that.
By the way you could do what you want using a simple Field
and the List
validator as follows:
from booby import models, fields, validators
class User(models.Model):
phones = fields.Field(validators.List(validators.String, validators.In(['a', 'b'])))
The point is to pass a list of validators for each list element to the List
constructor and then the List
validator to the Field
.
Example: class User(models.Model): letters = fields.ListField(validators.String, validators.In(choices=['a', 'b']))
, or
class User(models.Model): letters = fields.ListField(validators.List(validators.String, validators.In(choices=['a', 'b'])))
So if I create instance: u = User(phones=[12345]) u.validate()
Nothing raised, because LIstField ignores all validators that are not subclass of Model. It would be good to add that feature.
class TestListWithInners(object):