How do I add StackedInlines to another model when the model for the inlines has a foreignkey in it
I have created models for a an election project. I want the polling agent to collect and submit results from different parties. I want to add the VoteInline to the ElectionResult models so that the PollingAgent can fill in the result of the different party's and the votes scored.
I have created the following models and admin but I am getting the following error. How do I solve this?
class Election(models.Model): election_category = models.CharField(max_length=255) start_date = models.DateTimeField() end_date = models.DateTimeField() class PoliticalParty(models.Model): name = models.CharField(max_length=200) election = models.ForeignKey(Election, on_delete=models.CASCADE) class Candidate(models.Model): fullname = models.CharField(max_length=120) party = models.ForeignKey(PoliticalParty, on_delete=models.CASCADE) bio = models.TextField(blank=True, null=True) class PollingAgent(models.Model): candidate = models.ForeignKey(Candidate, on_delete=models.CASCADE) election = models.ForeignKey(Election, on_delete=models.CASCADE) fullname = models.CharField(max_length=120) phone = models.IntegerField() email = models.EmailField() class Vote(models.Model): party = models.ForeignKey(Candidate, on_delete=models.CASCADE) votes= models.IntegerField() class ElectionResult(models.Model): polling_agent = models.ForeignKey(PollingAgent, on_delete=models.CASCADE) votes = models.ForeignKey(Vote, on_delete=models.CASCADE) uploaded_on = models.DateTimeField(auto_now_add=True) class VoteInline(admin.StackedInline): model = Vote extra = 0 admin.site.register(Vote) @admin.register(ElectionResult) class ElectionResultAdmin(admin.ModelAdmin): inlines = [ VoteInline, ]
ERRORS: <class 'dashboard.admin.VoteInline'>: (admin.E202) fk_name 'party' is not a ForeignKey to 'dashboard.ElectionResult'.