Skip to main content

Form validator classes for django ModelForms

Project description

pypi travis codecov downloads


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):

class MyModelForm(FormValidatorMixin, forms.ModelForm):

    form_validator_cls = MyFormValidator

    class Meta:
        model = TestModel
        fields = '__all__'


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

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Files for edc-form-validators, version 0.1.40
Filename, size File type Python version Upload date Hashes
Filename, size edc_form_validators-0.1.40-py3-none-any.whl (33.0 kB) File type Wheel Python version py3 Upload date Hashes View

Supported by

Pingdom Pingdom Monitoring Google Google Object Storage and Download Analytics Sentry Sentry Error logging AWS AWS Cloud computing DataDog DataDog Monitoring Fastly Fastly CDN DigiCert DigiCert EV certificate StatusPage StatusPage Status page