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.38.tar.gz
(41.7 kB
view hashes)
Built Distribution
Close
Hashes for edc-form-validators-0.3.38.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | 8f395ecdfea2ed1ef8fcaa5d96c807dd2ddc6ee031c6ab5c7108a6aafe8b3758 |
|
MD5 | 2272c39e9fce806f45406d22ba90a72b |
|
BLAKE2b-256 | 29fc92a093d2ec5e022bd8b44b22c9fda38e3c468d048dd45b1559beb1bc6648 |
Close
Hashes for edc_form_validators-0.3.38-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 695301072409ceabd381a21e05d671ba96f4c934cf0c8f96b9d7990982f2b4bc |
|
MD5 | 2a70886647ab8167708c99f614f3dec8 |
|
BLAKE2b-256 | 8aad41e36870520cf5cfda1bea13cf6e2da57ab67fd3b59646679cbfdbb52f1a |