Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

94
Visualizações
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
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda