假設,我有下面兩個表: enter image description here如何與django連接表?
我做了models.py:
class Score(models.Model):
Student_Id = models.CharField(max_length=20, primary_key=True)
Grade = models.CharField(max_length=30)
Status= models.CharField(max_length=3)
class Meta:
db_table ='T_Score'
class Student(models.Model):
Student_Id = models.CharField(max_length=20, primary_key=True)
Student_Name = models.CharField(max_length=30)
Student_Class = models.CharField(max_length=3)
def __str__(self):
return {
"id" : self.Student_Id,
"name" : self.Student_Name,
}
class Meta:
db_table ='T_Student'
是否有可能加入表,如果Student.Student_Id就像主鍵(不作爲外國人)?我應該如何製作代表學生證,學生姓名和成績的view.py和模板? 預先感謝您。