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
Built Distribution
Close
Hashes for edc-form-validators-0.1.7.macosx-10.13-x86_64.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | 88c7915ac7ae35d8d6c300f76c86df9d093c13e98ce1aa1afd421224e4cd0ade |
|
MD5 | 041ffa1b1d7cc880687fd9f9f73224a0 |
|
BLAKE2b-256 | e26fc4f38a572b92cfcf04b17b8eea0b1011804591954ad003eda4b0ee203cec |
Close
Hashes for edc_form_validators-0.1.7-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | c3a38885eb54c2b1758b2d487be660c8ff12480e00b7820bb9135819a6eefb97 |
|
MD5 | 201e2563dcb00075fd0ea14f5aa93c4c |
|
BLAKE2b-256 | e90c71ae1917cc88ca71506b7f85ac56815884ebf076832e1aed97807bd3bdc9 |