1

I am using Colander for validation, and would like to validate one key based on another.

e.g: I would like to validate field value based on entity value:

class ValidationSchema(Validator.MappingSchema):
    entity = Validator.SchemaNode(Validator.String())
    field = Validator.SchemaNode(Validator.String(), missing=Validator.drop)

try:
    values = {"entity":"a", "field":"field1"}
    parameters = ValidationSchema().deserialize()
except Validator.Invalid as e:
    errors = e.asdict()
    return

If entity is a then field should be field1
If entity is b then field should be field2
If entity is not present then do not validate field key

How can this be implemented?

CATboardBETA
  • 418
  • 6
  • 29
vibhor Gupta
  • 103
  • 11

0 Answers0