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.33.tar.gz
(41.0 kB
view hashes)
Built Distribution
Close
Hashes for edc-form-validators-0.3.33.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | 5046dc9875c0c6d3630bfc46a83b36a3c11bd331747b413c3a996e827c02a547 |
|
MD5 | 2012e1f2a9f1dcd5f04a2178fedfdd36 |
|
BLAKE2b-256 | 00ba525f18b0b65f3452a206f6a74188d5128973002e6fe305a3092069001552 |
Close
Hashes for edc_form_validators-0.3.33-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 1a0f7fb78e47ab8328f941adc429934c6584ec2ada69d5c387cc4e68ebba1cd7 |
|
MD5 | 874b5d07a1616e200a2afd680d31c2f0 |
|
BLAKE2b-256 | 72a01767796e33e4e0ec8ce065bda5ed33e93aa36b84f8823ccedea002ed26a2 |