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.13.tar.gz
(37.7 kB
view hashes)
Built Distribution
Close
Hashes for edc-form-validators-0.3.13.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | 985f544d34fcba66ca1f1d9c6c40a4d45cb24c23a1922e17f4df132732d59c5c |
|
MD5 | b94f0321b793abf662b8896b29338680 |
|
BLAKE2b-256 | dee27e2192c3852358e85308d092a397467e732e94c1ad0e30a949aaa0856825 |
Close
Hashes for edc_form_validators-0.3.13-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | ecd41076d437b406bec4d89085a66474daa41a9ebcee96ec8c7ba62f0801f71b |
|
MD5 | 6d1ccdc0dc4d179beff3102b3b77acc9 |
|
BLAKE2b-256 | 797d137297e36ab99f10524169294f63bbc382a9c53d4bc2a56fa8b3c9f58f0b |