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.24.tar.gz
(39.0 kB
view hashes)
Built Distribution
Close
Hashes for edc-form-validators-0.3.24.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | bc7635a56fbc4c92619aef7bf938eb0ef8688362783f3c5d98316d0fdd30c109 |
|
MD5 | ddbd170daee42ea27eca9c13a32bcf40 |
|
BLAKE2b-256 | 86fba06b358f537b7ce8abb2606571b30ebafabb148d1105b20175fdce22e2cf |
Close
Hashes for edc_form_validators-0.3.24-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | d44a82281734da8855bcb2646398eeb5135978caefcec682d1f217fbac5cec08 |
|
MD5 | 2ae98d23b23d3a3fbc7515a7c577de28 |
|
BLAKE2b-256 | a6dab73adb3785ed4a30c2fe65df4c57f3e70e480396a47eb5dee80305b88c52 |