peewee-validates¶
Peewee ORM のための、シンプルかつフレキシブルなモデルとデータバリデータ。
必要事項¶
python >= 3.3
peewee >= 2.8.2 (including Peewee 3)
python-dateutil >= 2.5.0
使い方¶
peewee-validates でできることを以下にチラ見せします:
import peewee
from peewee_validates import ModelValidator
class Category(peewee.Model):
code = peewee.IntegerField(unique=True)
name = peewee.CharField(null=False, max_length=250)
obj = Category(code=42)
validator = ModelValidator(obj)
validator.validate()
print(validator.errors)
# {'name': 'This field is required.', 'code': 'Must be a unique value.'}
実際のところ、モデルさえ必要としない汎用的なバリデータもあります:
from peewee_validates import Validator, StringField
class SimpleValidator(Validator):
name = StringField(required=True, max_length=250)
code = StringField(required=True, max_length=4)
validator = SimpleValidator(obj)
validator.validate({'code': 'toolong'})
print(validator.errors)
# {'name': 'This field is required.', 'code': 'Must be at most 5 characters.'}
Contents¶
License¶
The MIT License (MIT)
Copyright (c) 2016 Tim Shaffer
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.