I have the following pydantic models
class Bar(BaseModel):
foo: int
class Foo(BaseModel):
bar: int
ba: Bar
Is there a way to access the bar
attribute from the Foo
model when running a validation on the foo
attribute of the Bar
model? I want to do something like this
class Bar(BaseModel):
foo: int
@validator('foo')
def validate_foo(cls, value, values):
if cls.bar > 1:
return 1
return 0
I've tried accessing the cls.__fields__
attribute but i've found nothing there, is there a better way to do this? Any advice is more than welcome.