I have a data model as below:
class School(models.Model):
name = models.CharField()
class Candidate(models.Model):
name = models.CharField()
school = models.ForeignKey(School)
class Skill(models.Model):
name = models.CharField()
school = models.ForeignKey(School)
class CandidateSkill(models.Model):
candidate = models.ForeignKey(Candidate)
skill = models.ForeignKey(Skill, related_name='candidate_skills')
And in the admin I have:
class CandidateSkillInline(admin.TabularInline):
model = CandidateSkill
form = CandidateSkillInlineForm
fields = ('skill', )
raw_id_fields = ('skill',)
class CandidateAdmin(admin.ModelAdmin):
model = Candidate
fields = ('name', 'school')
inlines = [CandidateSkillInline]
What I am trying to achieve is when I click the skill raw_id_field from the CandidateAdmin I want to list only the skills that belong to the school of the candidate. How can I achieve this?