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
Built Distribution
File details
Details for the file edc-form-validators-0.3.37.tar.gz
.
File metadata
- Download URL: edc-form-validators-0.3.37.tar.gz
- Upload date:
- Size: 41.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.11.5
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | bed1b26f95dc2a9a1527dd211e5bf3c15583ed919e6aa3a905445ebcd6ad1f2f |
|
MD5 | a01cd1f72d981413e0d6dc506836644a |
|
BLAKE2b-256 | a5318ea0d6c64489a8c31a029376bfb8b3dfd6f20647c065fea6f9a0d1d71cdc |
File details
Details for the file edc_form_validators-0.3.37-py3-none-any.whl
.
File metadata
- Download URL: edc_form_validators-0.3.37-py3-none-any.whl
- Upload date:
- Size: 48.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.11.5
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | df5dbb9456308af653b5f7d9b64480a62fe5a54124f7e59ef063a42c98c102c9 |
|
MD5 | d7b65facf58e5f1cb1e504e12203a40c |
|
BLAKE2b-256 | 0a7771d07856c215852a0e84634c603a1f1979bf5ba7904e7fe972ff76357dd6 |