Django model two fields in a table set foreign keys refer to two fields in another table

class products (models.Model):

MODE_CHOICES=(("week",""),("day",""))
productname=models.CharField(max_length=30,unique=True)
dutymode=models.CharField(max_length=30,choices=MODE_CHOICES,default="week")

class dutygroups (models.Model):

productname=models.ForeignKey("products",on_delete=models.CASCADE)
groupname=models.CharField(max_length=30)
startime = models.DateField()
class Meta:
    unique_together=("productname","groupname")


class persons (models.Model):

productname=models.ForeignKey("dutygroups",related_name="persons_productname",on_delete=models.CASCADE)
groupname=models.ForeignKey("dutygroups",related_name="persons_groupname",on_delete=models.CASCADE)
personname=models.CharField(max_length=30)

I am using django rest framework to design the API, of a duty table this is the model part, the first table is the product line and the corresponding duty mode, the second table is a mapping between the product line and the duty group, and the third table is the people in the group. Now I think the productname and groupname foreign keys of the third table to the productname and groupname, of the second table is a many-to-one relationship. I don"t know how to set these two fields?

Menu