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 field 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.35.tar.gz
(41.3 kB
view hashes)
Built Distribution
Close
Hashes for edc-form-validators-0.3.35.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | a966d771c7d3d1b8bd8783ad34869577be0e206a29bec8d68ef64bf3152f9942 |
|
MD5 | fbb657e21507692f2a7143f37499c0fe |
|
BLAKE2b-256 | 174d3969a046499da76f412b5e2fed8f73adcb400162ac8b67b0f4a2057fa371 |
Close
Hashes for edc_form_validators-0.3.35-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | cfc26eb02cdea226d54cadfc7cac0cbc99318a40051e778c8e8ce06bd96c7f8e |
|
MD5 | 52ae9121bbecde637cab86882ac43b61 |
|
BLAKE2b-256 | 23ccb2bbec709e25c55226b9f301522a729518ca6f220c400ad3dcf257abad6e |