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

186
Vistas
Django: How to use parent table fields in 'limit_choices_to'?

I have two classes System and Station which inherit from Base. The Base class has a foreign key to Group and Station has a foreign key to System.

I am trying to place a 'limit_choices_to' constraint on the latter FK, so that the related System has to be from the same Group as the Station.

Here's a snippet of the models.py

class Base(models.Model):
    group = models.ForeignKey(Group)

class System(Base):
    ...

class Station(Base):
    system_info = models.ForeignKey(System, limit_choices_to={'group': 'self.group'})

I've tried a number of ideas, including what is above, but no luck. Any help will be much appreciated!

about 4 years ago · Santiago Trujillo
1 Respuestas
Responde la pregunta

0

system_info = models.ForeignKey(System, limit_choices_to=Q(groups__name= 'group'))

I am hoping this will work. Group will be a group name created by you.

about 4 years ago · Santiago Trujillo Denunciar
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