I would like to do A>B validation when I have the following pydantic class, do you know how to do that?
class Test(BaseModel):
a: int
b: int
You can use validator method from pydantic:
from pydantic import validator
class Test(BaseModel):
a: int
b: int
@validator('b')
def ab_validation(cls, b, values, **kwargs):
if 'a' in values and b > values['a']:
raise ValueError('B is greater than A')
return b