2015-06-26 41 views
1

我使用Django来概述大学课程和高中学科要求之间的关系。Django属性的布尔组合

到目前为止,我有以下型号:

class Course(models.Model): 
    title = models.CharField(max_length=100) #(e.g. Bachelor of _____) 
    ft_years = models.SmallPositiveIntegerField() #years of full time study 

class Requirement(models.Model):  
    subject = models.CharField(max_length=50) #(e.g. Mathematics 3) 
    score = models.DecimalField(max_digits=3) #(e.g. 70)  
    percent = models.NullBooleanField() #True if score is in percent 

我的问题是,我怎么能添加要求的每场有布尔组合?

例如:

物理

甲本科(课程)具有以下要求:
(70物理%)AND(在数学3 OR 45%50%在数学4 )


附加信息:因为几门课程可能共享相同的要求(例如, 70%在物理学),但每门课程可能有几个要求,我打算使用m2m模型。

回答

1

你可以做一个CompoundRequirement具有一定数目的要求,它ORš在一起(使用ManyToManyField),然后每个类都有一些Requirement S和一些CompoundRequirement秒。 ANDs由多个需求来处理,所以你需要处理的是ORs。

+0

谢谢,但是对于“R1 OR(R2 AND R3)”这个工作如何工作,因为嵌套的AND不能被课程处理? – ZG101

+0

我在想也许是一个CompoundANDRequirement类呢? – ZG101

+0

取决于你想要关系能够走多深。我真的不知道如何在数据库中很好地扩展它。 –