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.40.tar.gz
(41.7 kB
view hashes)
Built Distribution
Close
Hashes for edc-form-validators-0.3.40.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | c226e3e75cfc4b4803ce937fe5fdc95358ac18a3d7bec618d1e236d8230c6fd7 |
|
MD5 | 9b9cfb329b6f1c04428c74b44ffa4d70 |
|
BLAKE2b-256 | ed1d373e2f6d740323f136ad08cfd64d5d74ea669b8d53700cb86f424ce6e79e |
Close
Hashes for edc_form_validators-0.3.40-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | b577b7b8327ac8e0382e190aa68dcd4d4f6cf1787293a75d573ce097ec700526 |
|
MD5 | 6cfa715b25b62b3546db8527b02626f9 |
|
BLAKE2b-256 | f627823864ed8e5384758a9747d4eb8ee189fd6505ef20b19eb545105e6fbd61 |