I have the following Models:
class Organizations(models.Model):
name = models.CharField(max_length=30,unique=True)
class Postcodes(models.Model):
organization = models.ForeignKey(Organizations,on_delete=models.PROTECT)
postcode = models.PositiveBigIntegerField()
class Agent(models.Model):
organization = models.ForeignKey(Organizations,on_delete=models.PROTECT)
name = models.CharField(max_length=50)
class AgentPostcodes(models.Model):
agent= models.ForeignKey(Agent,on_delete=models.PROTECT)
postcode = models.ForeignKey(Postcodes,on_delete=models.PROTECT)
and admin.py is
class AgentPostcodesInline(admin.TabularInline):
model = AgentPostcodes
class AgentAdmin(admin.ModelAdmin):
list_display = ['organization','name']
inlines = [AgentPostcodesInline]
How can I have the inline form fields filtered based on organization for postcodes related to that organization only. Currently it shows postcodes for all organizations even not related to the agent.