[Answered ]-Referring to associated field in another model in Django

1👍

If you have a through=… model [Django-doc], then that model needs two ForeignKeys: one to the "source" model, and one to the Target model, since a ManyToManyField is always a model (sometimes an implicit) one that has two ForeignKeys to link two other models together: it is implemented as a junction table [wiki].

class Season(models.Model):
    season = models.CharField(max_length=10)
    buyer = models.ForeignKey(Buyer, on_delete=models.CASCADE)
    fruit = models.ForeignKey(Fruit, on_delete=models.CASCADE)

Leave a comment