schema
schema copied to clipboard
Validation depending on attribute of the instance
Is there any chance to enable the following function:
In the schema, there is an 'pet_type', which may take value from ('dog', 'cat'). There is also an attribute of 'pet_food', whose legitimate value depends on 'pet_type' - if it is a dog, then 'pet_food' can take value from ('dog_food_1', 'dog_food_2') , and if it is a cat, then 'pet_food' can take value from ('cat_food_1', 'cat_food_2').
This is quite needed for my ongoing project. Thank you!
I'm looking for a similar feature. in my case that given two dates one is smaller than another. Can items really only be validated in isolation?
So far, I'm afraid so. I'm not sure what it would take to change this, as the library is written with fields being independent of each other.
I've just realized that in my case I can get what I want with something like
And({'from':str, 'to':str}, lambda d:d['from'] < d['to']).validate({'from':'2016-01-01', 'to':'2017-01-01'})
Since I'm validating a dict, I can also use a validation function on the dict as a whole.