class If(object):

    def __init__(self, parent, run_validation=None, extra_validators=None,
        msg=None):
        self.parent = parent
self.msg = msg if msg is not None else 'Invalid'
if callable(run_validation):
    self.run_validation = run_validation
else:
    _run_validation = lambda self, parent, form: parent.data == run_validation
self.run_validation = _run_validation
self.extra_validators = extra_validators if extra_validators is not None else [
    ]

def __call__(self, field, form):
    parent = getattr(form, self.parent)
if self.run_validation(parent, form):
    return field.validate(form, extra_validators=self.extra_validators)
Как правильно построить форму с повторяющимися элементами