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 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.19.tar.gz
(37.8 kB
view hashes)
Built Distribution
Close
Hashes for edc-form-validators-0.3.19.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | fd4f16fae972e4338a200b87e3008484df738844a550bad941a4918c1ec93336 |
|
MD5 | f8996a24f40d9b0853f21234c6c20f10 |
|
BLAKE2b-256 | 548b201483932e1edf816ac624a938405bcccb53122b7d9fc46e5daab51a6de8 |
Close
Hashes for edc_form_validators-0.3.19-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 80258ffb1ae2918bdb7ec3465b7e9e00bb7488aa760a81cc367b5a6328b77bd9 |
|
MD5 | 39f5e3c905b4bc53c6c50d00008114de |
|
BLAKE2b-256 | 8ed1c8b4c38a0e2b294e02632ec1b52442ca404ea5d5d5cfdbf3fe402c002e32 |