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

185
Views
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 answers
Answer question

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 Report
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!