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 (including Peewee 3)
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.7.tar.gz
(10.4 kB
view details)
Built Distribution
File details
Details for the file peewee-validates-1.0.7.tar.gz
.
File metadata
- Download URL: peewee-validates-1.0.7.tar.gz
- Upload date:
- Size: 10.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 8207de77a7482229a68380a4a9af95e0ddbfa0b27464ca0f542d5b2e469c1a55 |
|
MD5 | 04736930c52f6c787113a4aa7bb0778a |
|
BLAKE2b-256 | f9c34beba6c4780046d434200513f322c60334182aac94a5983ae27d508392e3 |
File details
Details for the file peewee_validates-1.0.7-py2.py3-none-any.whl
.
File metadata
- Download URL: peewee_validates-1.0.7-py2.py3-none-any.whl
- Upload date:
- Size: 11.2 kB
- Tags: Python 2, Python 3
- Uploaded using Trusted Publishing? No
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | be9b31821f4204be01672db72bee63c359f68cfa543cabb7c6e89b2250ddfc9b |
|
MD5 | 6bfc63cbb478ff4398ddd92a3da8f2f2 |
|
BLAKE2b-256 | aaed6165cffefac66d286689ba70e96d0f6694e505dc6ae98c9b22af73ac3c43 |