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.39.tar.gz
(41.7 kB
view hashes)
Built Distribution
Close
Hashes for edc-form-validators-0.3.39.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | 97d76649c28074407414f5f656c1076c4a5ce734b305503579113bbe1fb9ed63 |
|
MD5 | afc234ef65f2b2a4990f33260be88222 |
|
BLAKE2b-256 | 814b3245ffc90aa2424d2905c73026d0214b66fb88c48687b0302039df376fe3 |
Close
Hashes for edc_form_validators-0.3.39-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 1cde8f003fbdc0a6c3689745e6b2497a5dd04773ca081fb12f279cf45e8caaf6 |
|
MD5 | 692992a68de82d0e7c774719f1e8a941 |
|
BLAKE2b-256 | bb27c931168a96d08ac6617c0d2c4f479862530eff532cc296216f72ada7e3f4 |