Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

92
Views
Shared attribute in pydantic BaseModel

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.

over 4 years ago · Santiago Trujillo
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!