我是django初学者。
我这里有两个模型在另一个模型中用作 ManyToManyField:
在models.py中:
class Likelihoods(models.Model):
Likelihood = models.CharField(primary_key=True, max_length=255)
Param = models.CharField(max_length=255)
class Consequences(models.Model):
Consequence = models.CharField(primary_key=True, max_length=255)
Param = models.CharField(max_length=255)
class Inherent_risks(models.Model):
Likelihood = models.ManyToManyField(Likelihoods, related_name= 'InherentRisk_Likelihood')
Consequence = models.ManyToManyField(Consequences, related_name= 'InherentRisk_Consequence')
在此之后,我将它添加到另一个模型以创建一个表单名称
Hira
.
class Hira(models.Model):
Activity = models.CharField(max_length=255)
Risk_Description = models.TextField(default="***")
PBS = models.ManyToManyField(PBS)
Physical_control = models.CharField(max_length=255)
Administrative_control = models.CharField(max_length=255)
Instrumented_control = models.CharField(max_length=255)
Inherent_Risk = models.ForeignKey(Inherent_risks, on_delete=models.CASCADE, related_name='Inherent_risk' )
form.py:
class HiraForm(ModelForm):
class Meta:
model = Hira
fields = '__all__'
likelihood
和consequence
(甚至没有任何数据)。
我做错了什么?