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.17.tar.gz
(37.7 kB
view hashes)
Built Distribution
Close
Hashes for edc-form-validators-0.3.17.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | d699bc33793728a8c16b95dbe2439c6a5d97f90ccd9a476e4a8538164b1df042 |
|
MD5 | 4aaeeac0ed63102a5b291f85171f9d0f |
|
BLAKE2b-256 | 2c5cf209d1a45872a8f2ffb0f3ed92e5ebdf0e3074bcf09a231861fc27000332 |
Close
Hashes for edc_form_validators-0.3.17-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | b95a880052b0bcdc130678ca8b336a1816ea51e141b781a7e80749116b98c652 |
|
MD5 | 434767267f424ecbd248aea3c4a23d06 |
|
BLAKE2b-256 | 6ea1c1c978a533edf218cc2dbf815a691d2e2d6f824772d8d401882ee9ca2a2f |