我有嵌套多对多关系的模型
IndependentTest与Protocols有多对多的关系
和Protocols与Format有多对多的关系。
所以我需要针对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 中,但其他数据,如测试日期或地点呢?