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.36.tar.gz
(41.5 kB
view hashes)
Built Distribution
Close
Hashes for edc-form-validators-0.3.36.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | 37d383df0ccca684a50d7e70a07375de2f68418b759ba4133cead0eb26dfa227 |
|
MD5 | f376546f46ab15d8184855c17c1862bd |
|
BLAKE2b-256 | 486236222853761ba5d41e7c10335086b38be3f1acbc9d845ad983916906629b |
Close
Hashes for edc_form_validators-0.3.36-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 43677375dabb37dcb134193399496c26a92de2bb3c5ae79c8a45b3190d910689 |
|
MD5 | 1a2e592939525f73ea51d9fbe1681ff8 |
|
BLAKE2b-256 | 075e2401957fc48c3f8df84878b3e486c40804ed28d66fff7924ed4e14902d10 |