我的模型具有嵌套的多对多关系
IndependentTest 与协议有多对多关系
和协议与格式有多对多的关系。
所以我需要针对 IndependentTests 为特定用户保存测试结果。
编辑:以下是模型
class IndependentTest(models.Model):
name = models.CharField(max_length=1000)
choice = models.ManyToManyField(to=TestChoice, null=True, blank=True)
required = models.BooleanField()
testType = models.CharField(max_length=200,
choices=Values.CUSTOM_ATTRIB_TYPES)
class TestProtocol(models.Model):
name = models.CharField(max_length=200)
description = models.CharField(max_length=1000)
independent_test = models.ManyToManyField(IndependentTest,
through='PIOrder')
class PIOrder(models.Model):
protocol = models.ForeignKey(TestProtocol)
independent = models.ForeignKey(IndependentTest)
order = models.IntegerField()
class TestFormat(models.Model):
name = models.CharField(max_length = 100)
test_protocol = models.ManyToManyField(TestProtocol, through='FPOrder')
class FPOrder(models.Model):
format = models.ForeignKey(TestFormat)
protocol = models.ForeignKey(TestProtocol)
order = models.IntegerField()
编辑:我不知道这是不是一个好方法,但我可以创建一个新类
class CandidateTest (models.Model):
test_value = models.CharField(max_length = 200)
candidate = models.ForeignKey(Candidate)
test = models.ForeignKey(IndependentTest)
testProtocol = models.ForeignKey(TestProtocol)
testFormat = models.ForeignKey(TestFormat)
虽然结果会保存在test_value中,但是测试的日期或地点等其他任何数据呢?