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.5.macosx-10.13-x86_64.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | c87584868960aa36c86d59a926fd8fb429882798145b34b5125c9957261839be |
|
MD5 | 90e9962eeac3a180b43a651b1d8ca990 |
|
BLAKE2b-256 | 4434b764147ffae5bada90b67a71fb8a924b2f29d3779f3775e046d2684b2221 |
Close
Hashes for edc_form_validators-0.1.5-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 213b2bd665c1ed5d91d5a66407fe36e335f242848a104a0480d3b7a86fb3f2b1 |
|
MD5 | 7ffa26dab97c5b76d4f80f59116a6cf1 |
|
BLAKE2b-256 | 21fd2bfbd2ced65beb362108292d2b9e77443a6520981cf3e7b4a662261bbfeb |