创建学生表
class Student(models.Model):
s_name = models.CharField(max_length=10,unique=True,verbose_name='姓名')
s_age = models.IntegerField(default=19,verbose_name='年龄')
s_sex = models.BooleanField(default=1,verbose_name='性别')
create_time = models.DateTimeField(auto_now_add=True,verbose_name='创建时间')
operate_time = models.DateTimeField(auto_now=True,verbose_name='修改时间')
math = models.DecimalField(max_digits=4,decimal_places=2,null=True)
chinese = models.DecimalField(max_digits=4, decimal_places=2,null=True)
class Meta:
db_table = 'app_student'
创建学生信息表
class StudentInfo(models.Model):
phone = models.CharField(max_length=11, null=True, unique=True, verbose_name='电话号码')
address = models.CharField(max_length=50, null=True, verbose_name='地址')
class Mete:
db_table = 'student_info'
与学生表实现一对一关联(该代码添加到学生表下面)
stu_info = models.OneToOneField(StudentInfo,null=True,related_name='stu')
创建班级表
class Grade(models.Model):
g_name = models.CharField(max_length=10, unique=True, verbose_name='班级名称')
class Meta:
db_table = 'grade'
与学生表实现一对多联系(该代码添加到学生表下面)
g = models.ForeignKey(Grade,null=True,related_name='stu')
创建选课信息表
class Course(models.Model):
c_name = models.CharField(max_length=10,null=True)
class Meta:
db_table = 'course'
与学生表实现多对多联系(该代码添加到学生表下面)
c = models.ManyToManyField(Course,null=True)