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.22.tar.gz
(38.8 kB
view hashes)
Built Distribution
Close
Hashes for edc-form-validators-0.3.22.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | 1375302940f352636022ef3408acc63a3939638dc4a87a0179237384d38dc38d |
|
MD5 | 2f75b7ee3fa86c76dcab5dd8d4c584fe |
|
BLAKE2b-256 | 5a194c97790d743af0608f294bca6fc443170e253f177cb0f65b2b7980a7728f |
Close
Hashes for edc_form_validators-0.3.22-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 4591515debcf0d8dade640d1fae7ef667798e41b8f445bd3f373df328aa82957 |
|
MD5 | 2f0b8f1d1297991a0f92c7d9d4c28d2c |
|
BLAKE2b-256 | 1fc80706e7788d3213bdce794b72893ca313e26116ea74c71baa2c56cb8aa548 |