Form validator classes for common patterns in 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
edc-form-validators-0.3.18.tar.gz
(37.7 kB
view hashes)
Built Distribution
Close
Hashes for edc-form-validators-0.3.18.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | b08a40769b8576901bb79eac4e3b344291066f2d359eae11bbedf2beba727159 |
|
MD5 | d5c0cf36b3c857961f5879873783af3d |
|
BLAKE2b-256 | c856c2fe3927b2c13953edab97afa216c24d7fa690be66488edd040a3c1cf982 |
Close
Hashes for edc_form_validators-0.3.18-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | daab1b0c764f2abd886813561805e88895d275f17d13ff9b78db45f618766d26 |
|
MD5 | 288ae39da2a2e646cef3f1a2f6bc075c |
|
BLAKE2b-256 | 186c2d638e6b3a0a67cc384fa7af8090734376a9eecb1afed37880cb53c414c6 |