Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

93
Vistas
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 la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda