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.32.tar.gz
(41.1 kB
view hashes)
Built Distribution
Close
Hashes for edc-form-validators-0.3.32.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | 27c83a9cf8b3ceabdd1771d8fe5b380d191f83b1ef888bf7b4aacd9b64d617aa |
|
MD5 | be686fcd172ab57dfce520fc3ea60b7c |
|
BLAKE2b-256 | 57476037cbc87f527e79c5a06570a60268dad5a673dd6dc480faee8ec3232ca6 |
Close
Hashes for edc_form_validators-0.3.32-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 0c6bdc52bc40a9875a7902c1fb929fc44efc38008eb17b1045cac03d0feb7479 |
|
MD5 | 62b0f990719e5a242c2afbd21cf6d457 |
|
BLAKE2b-256 | 94e91cf91fbb164b1882a975129826c3c11642ccf8b0e91db896769490b83d8d |