Home > Software design >  Table relations with django models
Table relations with django models

Time:01-02

I am having models for subjects like English , Biology and so on. and in the other side I have a model called teachers that store records of teachers .I am working on with Django and the problem is that I don't know how could I create the many to many relationship between teachers and the subjects what am trying to achieve is to assign the responsibility of teachers. I tried to make the models English ,Biology and others into one model called Subjects and later to use Manytomanyfield, but the frequencies are totally different and I stacked. some of my models are listed below.

`class English(models.Model): studentID = models.IntegerField()

l_1 = models.DecimalField(max_digits=5, decimal_places=2, default=0)
s_1 = models.DecimalField(max_digits=5, decimal_places=2, default=0)
r_1 = models.DecimalField(max_digits=5, decimal_places=2, default=0)
w_1 = models.DecimalField(max_digits=5, decimal_places=2, default=0)
hw_1 = models.DecimalField(max_digits=5, decimal_places=2, default=0)
t_1 = models.DecimalField(max_digits=5, decimal_places=2, default=0)
p_1 = models.DecimalField(max_digits=5, decimal_places=2, default=0)

l_2 = models.DecimalField(max_digits=5, decimal_places=2, default=0)
s_2 = models.DecimalField(max_digits=5, decimal_places=2, default=0)
r_2 = models.DecimalField(max_digits=5, decimal_places=2, default=0)
w_2 = models.DecimalField(max_digits=5, decimal_places=2, default=0)
hw_2 = models.DecimalField(max_digits=5, decimal_places=2, default=0)
t_2 = models.DecimalField(max_digits=5, decimal_places=2, default=0)
p_2 = models.DecimalField(max_digits=5, decimal_places=2, default=0)



def get_mark_30_first(self):
    sum = self.l_1 self.s_1  self.r_1   self.w_1   self.hw_1   self.t_1  self.p_1
    return sum

def get_mark_30_second(self):
    sum = self.l_2 self.s_2  self.r_2   self.w_2   self.hw_2   self.t_2  self.p_2
    return sum

def getMark_60(self):
    return self.get_mark_30_second() self.get_mark_30_first()`

.....

class Biology(models.Model):
studentID = models.IntegerField()
l_2 = models.DecimalField(max_digits=5, decimal_places=2, default=0)
cw_1 = models.DecimalField(max_digits=5, decimal_places=2, default=0)
hw_1 = models.DecimalField(max_digits=5, decimal_places=2, default=0)
hw_2 = models.DecimalField(max_digits=5, decimal_places=2, default=0)
l_1 = models.DecimalField(max_digits=5, decimal_places=2, default=0)
pro_1 = models.DecimalField(max_digits=5, decimal_places=2, default=0)
pn_1 = models.DecimalField(max_digits=5, decimal_places=2, default=0)
t_1 = models.DecimalField(max_digits=5, decimal_places=2, default=0)

cw_2 = models.DecimalField(max_digits=5, decimal_places=2, default=0)
cw_3 = models.DecimalField(max_digits=5, decimal_places=2, default=0)
hw_3 = models.DecimalField(max_digits=5, decimal_places=2, default=0)
pn_2 = models.DecimalField(max_digits=5, decimal_places=2, default=0)
t_2 = models.DecimalField(max_digits=5, decimal_places=2, default=0)
pro_2 = models.DecimalField(max_digits=5, decimal_places=2, default=0)

CodePudding user response:

How about if you use foreign key or many to many field of teacher's model in your English, Biology and other subject's models?

  • Related