We've used field-level validation quite a bit and it is wonderful and powerful. There are times, though, the document itself is valid only by assessing more than one field. Changing any field involved must trigger the validation.
What we've done for now is apply the validation to each field involved - which runs the validation multiple times on POST.
Is there a way to apply a validation rule to the document itself?
e.g. let's say some_thing has two fields and validation considers both fields. If either one changes, we must validate against the other.
This works...
The validator (simplified for clarity):
def _validate_custom_validation(self, custom_validation, field, value):
if field == "field1":
f1 = value
f2 = self.document.get('field2')
if field == "field2":
f1 = self.document.get('field1')
f2 = value
if custom_validation and not is_validate(f1, f2):
self._error(field, "validation failed...")
then the schema definition:
DOMAIN = {
some_thing: {
schema: {
field1: {
'type': 'string',
'custom_validation': True
},
field1: {
'type': 'string',
'custom_validation': True
}
}
}
}
But we would like to do something like this:
The validator
def _validate_custom_validation(self, custom_validation):
f1 = self.document.get('field1')
f2 = self.document.get('field2')
if custom_validation and not is_validate(f1, f2):
self._error(resource, "validation failed...")
then the schema definition:
DOMAIN = {
some_thing: {
'custom_validation': True,
schema: {
field1: {
'type': 'string'
},
field1: {
'type': 'string'
}
}
}
}
Is this possible?