Simple and flexible model validator for Peewee ORM.
Project description
A simple and flexible model and data validator for Peewee ORM.
Requirements
python >= 3.3
peewee >= 2.8.2
python-dateutil >= 2.5.0
Installation
This package can be installed using pip:
pip install peewee-validates
Usage
Here’s a quick teaser of what you can do with 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.'}
In fact, there is also a generic validator that does not even require a model:
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.'}
Documentation
Check out the Full Documentation for more details.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
peewee-validates-1.0.2.tar.gz
(10.3 kB
view hashes)
Built Distribution
Close
Hashes for peewee_validates-1.0.2-py2.py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 2e60169cc35bcf0191d1914da74310f3dc942fa807fb31a2b743c4bec3d8c56b |
|
MD5 | b188a049f1c1daf9cba6eb99e77d7f5c |
|
BLAKE2b-256 | 689a9e449c6a94041caac71aeda352f0128174c5050a486cf7e4a17cf8eb2999 |