Form validator classes for django ModelForms
Project description
edc-form-validators
Form validator classes for ModelForms
ModelForm FormValidator
FormValidator simplifies common patterns used in ModelForm.clean. For example, if there is a response to field A then there should not a be response to B and visa-versa.
Declare a form with it’s form_validator class and use FormValidatorMixin:
class MyFormValidator(FormValidator):
def clean(self):
self.required_if(
YES,
field='f1',
field_required='f2')
...
class MyModelForm(FormValidatorMixin, forms.ModelForm):
form_validator_cls = MyFormValidator
class Meta:
model = TestModel
fields = '__all__'
Testing
Test the form_validator without having to instantiate the ModelForm:
def test_my_form_validator(self):
options = {
'f1': YES,
'f2': None}
form_validator = MyFormValidator(cleaned_data=options)
self.assertRaises(ValidationError, form_validator.validate)
self.assertIn('f2', form_validator._errors)
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
Built Distribution
Close
Hashes for edc-form-validators-0.1.8.macosx-10.13-x86_64.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | 5550c162a495bdb35e17d1f41de11ece761fd6314c567457cec23617ee54439d |
|
MD5 | 3ead2a78c23bbe630e6d1a04afebd55e |
|
BLAKE2b-256 | b9ed6e855e244c76b58a30a8413e00de3637aa76f3ce451cff52e6444d038405 |
Close
Hashes for edc_form_validators-0.1.8-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 1247f954e65b245446771bb398fb8a4cf3875af4df46748eb0fb1521655046e1 |
|
MD5 | 76f5d2b2c6fe4ce76dd584dff7c1ad61 |
|
BLAKE2b-256 | 0a7832b199814b30844f73d89194d317dd2af6032d6563e993f2c263e36dce5b |