一、新建app->courses
二、courses app 下有多个表存在:
1.Course-课程基本信息
2.Lesson-章节基本信息
3.Vedio-视频
4.CourseResource-课程资源
三、app的设计
1.课程设计(TextField不用表明长度,可以输入无限长。因为有datetime,所以要导入时间:from datetime import datetime)
class Course(models.Model):
name=models.CharField(max_length=50,verbose_name=u"课程名称")
desc=models.CharField(max_length=300,verbose_name=u"课程描述")
detail=models.TextField(verbose_name=u"课程详情")
degree=models.CharField(choices=(("cj","初级"),("zj","中级"),("gj","高级")),max_length=2)
learn_times=models.IntegerField(default=0,verbose_name=u"学习时长(分钟)")
students=models.IntegerField(default=0,verbose_name=u"学习人数")
fav_nums=models.IntegerField(default=0,verbose_name=u"收藏人数")
image=models.ImageField(upload_to="courses/%Y/%m",verbose_name=u"封面图",max_length=100)
click_nums=models.IntegerField(default=0,verbose_name=u"点击数")
add_time=models.DateTimeField(default=datetime,verbose_name=u"添加时间")
class Meta:
verbose_name=u"课程"
verbose_name_plural=verbose_name
2.章节设计
课程和章节是一对多的关系,利用外键的形式来完成(class 和class Meta 之间要空两行)
外键:models.ForeignKey
class Course(models.Model):
name=models.CharField(max_length=50,verbose_name=u"课程名称")
desc=models.CharField(max_length=300,verbose_name=u"课程描述")
detail=models.TextField(verbose_name=u"课程详情")
degree=models.CharField(choices=(("cj","初级"),("zj","中级"),("gj","高级")),max_length=2)
learn_times=models.IntegerField(default=0,verbose_name=u"学习时长(分钟)")
students=models.IntegerField(default=0,verbose_name=u"学习人数")
fav_nums=models.IntegerField(default=0,verbose_name=u"收藏人数")
image=models.ImageField(upload_to="courses/%Y/%m",verbose_name=u"封面图",max_length=100)
click_nums=models.IntegerField(default=0,verbose_name=u"点击数")
add_time=models.DateTimeField(default=datetime,verbose_name=u"添加时间")
class Meta:
verbose_name=u"课程"
verbose_name_plural=verbose_name
class Lesson(models.Model):
course=models.ForeignKey(Course,verbose_name=u"课程")
name=models.CharField(max_length=100,verbose_name=u"章节名")
add_time=models.DateTimeField(default=datetime.now,verbose_name=u"添加时间")
class Meta:
verbose_name=u"章节"
verbose_name_plural=verbose_name
class Video(models.Model):
lesson=models.ForeignKey(Lesson,verbose_name=u"章节")
name=models.CharField(max_length=100,verbose_name=u"视频名")
add_time=models.DateTimeField(default=datetime.now,verbose_name=u"添加时间")
class Meta:
verbose_name=u"视频"
verbose_name_plural=verbose_name
class CourseResource(models.Model):
course=models.ForeignKey(Lesson,verbose_name=u"课程")
name=models.CharField(max_length=100,verbose_name=u"名称")
download=models.FileField(upload_to="course/resource/%Y/%m",verbose_name=u"资源文件",max_length=100)
add_time=models.DateTimeField(default=datetime.now,verbose_name=u"添加时间")
class Meta:
verbose_name=u"课程资源"
verbose_name_plural=verbose_name