Python Day 59 Django framework

  ##

# Teachers and students table tables may be one-many relationship, you can create a third table associated manually when construction of the table 

class Student (models.Model): 
    name = models.CharField (= 32 max_length, null = True) 
    Age models.CharField = (= 32 MAX_LENGTH, null = True) 

class Teacher (models.Model): 
    name = models.CharField (= 32 MAX_LENGTH, null = True) 
    Gender = models.CharField (= 32 MAX_LENGTH, null = True) 

# the establishment of the third table, two tables together before the association 
class TeacherToStudent (models.Model): 
    STU = models.ForeignKey ( ' Student ' , null = True) 
    TEAC = models.ForeignKey (' Teacher ' , null = True)
     class Meta -:
     # United unique index 
        unique_together = [ 
            ( ' STU ' , ' TEAC ' ),             
    ]

 

Guess you like

Origin www.cnblogs.com/liangzhenghong/p/11202192.html