Form validator classes for 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.8.tar.gz
(29.0 kB
view hashes)
Built Distribution
Close
Hashes for edc-form-validators-0.3.8.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | 43a9f6d3e22d5a6fcc63e191d9ec62e68ac19c7b81ba6887177567f5d2c6791b |
|
MD5 | 8b5b84df4a0bd58793da7e5677fca236 |
|
BLAKE2b-256 | feb2e73e53c4345f0d2d21f37d6a547e838b596d692034a063fe2015162fd73e |
Close
Hashes for edc_form_validators-0.3.8-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 1fe5c32d12b0197ab3a4856510fe8d5536da5c402257d1e414765a40444587c5 |
|
MD5 | 0195bf9d67e35734643fcd1be6e10018 |
|
BLAKE2b-256 | 381269b4da0f4f1e5c1e71c92ef7a12aa48559ea6ba6d4ffde002870270fcaaf |