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