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 Distribution
edc-form-validators-0.3.7.tar.gz
(28.5 kB
view hashes)
Built Distribution
Close
Hashes for edc-form-validators-0.3.7.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | 1543f5ced9e609a5ba435eba9bbec9c940cae7848a649fdf32ad9fe41e0a7d67 |
|
MD5 | 6085f1e036b5943df554a51f4e71de99 |
|
BLAKE2b-256 | f89e9949ee75a68509ab4c000136aa501834f445139aadd1e08d367369f2cb79 |
Close
Hashes for edc_form_validators-0.3.7-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 64005c58f6f5e9a96a5fae46f05d6084119ee7fb90a13de5aab5157c67227192 |
|
MD5 | 888699455721a8c3adfee1040fa215e5 |
|
BLAKE2b-256 | 9406feea8c65c9277fc9a17cb1016591e7ff73360692a8f697b64f65ba336cec |