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.14.tar.gz
(37.7 kB
view hashes)
Built Distribution
Close
Hashes for edc-form-validators-0.3.14.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | f1e3f0a8aaac18ab2dada1da60ec2c91b766681bf517bf560d0749323731524b |
|
MD5 | 055e0004a097f43a4503dc4bfc21e73f |
|
BLAKE2b-256 | 957459e7f489d2c44608468f0259e353eef41727e573d530d74de98c712349e3 |
Close
Hashes for edc_form_validators-0.3.14-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 0742d21f16a71716f2c13f7f8f7d4ccf21e97dd186886ae8f0352e3663462519 |
|
MD5 | 4583b4faf0a864b7c472978f9322cc8a |
|
BLAKE2b-256 | b89bc4f04386671b071f4ee7e1b988d6f208021e53f61725d1243b8efbe6ecd4 |