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.16.tar.gz
(37.7 kB
view hashes)
Built Distribution
Close
Hashes for edc-form-validators-0.3.16.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | 1ab68a9b7c69e76c05951a51f3c9bdd2b709fc26245050f2b712ebafb17b0932 |
|
MD5 | 3f866f79b5d6ebbcfdb0b8ec0005a95b |
|
BLAKE2b-256 | 9caf86b14d93bfc68175ef4415ccb74cd2127f7e48e3ffa4deb22789babf58fe |
Close
Hashes for edc_form_validators-0.3.16-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 39414cd991bfb2b94e35730f91b5dc3e8f19bfe9d5f1a3a1c9e649c6058453a1 |
|
MD5 | 217510ec28067523e53aa7873616a049 |
|
BLAKE2b-256 | 20c4d817cf99612363dbc34e886622f95d4108178223caaad7ef1861448e7505 |