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 Distributions
No source distribution files available for this release.See tutorial on generating distribution archives.
Built Distribution
File details
Details for the file edc_form_validators-0.1.12-py3-none-any.whl
.
File metadata
- Download URL: edc_form_validators-0.1.12-py3-none-any.whl
- Upload date:
- Size: 27.1 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/1.13.0 pkginfo/1.5.0.1 requests/2.21.0 setuptools/40.6.2 requests-toolbelt/0.9.1 tqdm/4.31.1 CPython/3.7.2
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | e88e3ac867b361a4b8b25d843328ab8802517a140cf1396a8986be0a32126a2e |
|
MD5 | b431e0b7c8267edba31900803cb4f411 |
|
BLAKE2b-256 | ca1de79889fb2c09927849b46187aad18461bef70ffed9a3ff8e6b88bf97899c |