Hello I have been deliberating over this for ages and would like someone’s opinion.
I have the following three models:
class Commodity(models.Model): commodity = models.CharField(max_length=50, primary_key=True, unique=True)
class Variety(models.Model): commodity = models.ForeignKey(Commodity, on_delete=models.PROTECT, related_name='Variety') variety_name = models.CharField(max_length=50, unique=True)
class Weighbridge(models.Model): tn = models.AutoField(primary_key=True) variety_chosen = models.ManyToManyField(to=Variety, related_name='weighbridge')
The relationship I am trying to capture is this:
My question is - is it correct to explicitly write commodity as a foreign key to both weighbridge and variety or is it ok to leave it the way I have done in the code - where the relationship between weighbridge and variety is the only one explicitly defined?
Weighbridges should have a ForeignKey relationship to Commodity but is the implicit relationship through variety enough?
Any opinions would be greatly appreciated.
Thanks in advance,