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.26.tar.gz
(39.3 kB
view hashes)
Built Distribution
Close
Hashes for edc-form-validators-0.3.26.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | 40e5a96f29f7b5c38a911078354df46d2d51e4e2c1d9209d2542ae3da959132f |
|
MD5 | 64fdc2920030a8a824beaab71bba4e15 |
|
BLAKE2b-256 | 17e779fd189394e3127b8c112faf1c01cdf47ebf31bd97c8657abfb588d5f0ef |
Close
Hashes for edc_form_validators-0.3.26-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 2b5c8f4d4e23a02b6bd23ec05f06cbfddf01efe7de0116b73fb480542272d108 |
|
MD5 | e136aa7bee1bdf7efc1be07c0aaec987 |
|
BLAKE2b-256 | a2af27ac0b13903fe4d363f8c980785c6a2108802605173ad683521682bbd145 |