码迷,mamicode.com
首页 > 其他好文 > 详细

[py]django课程模型

时间:2018-01-29 22:31:57      阅读:184      评论:0      收藏:0      [点我收藏+]

标签:高级   image   for   int   nts   资源   add   key   desc   

课程模型分析

分3个表
技术分享图片
先设计课程表, 这是1

在设计lesson表,添加一个外键,course.

课程 1 course
章节 n lesson
视频 n video
资源 n courseresourse

课程表的字段如下:

技术分享图片

代码

技术分享图片

from datetime import datetime

from django.db import models


# Create your models here.

class Courses(models.Model):
    name = models.CharField(max_length=50, verbose_name="课程名")
    desc = models.CharField(max_length=300, verbose_name="课程描述")
    detail = models.TextField(verbose_name="课程详情")
    degree = models.CharField(choices=(("cj", "初级"), ('ZJ', "中级"), ("GJ", "高级")), verbose_name="课程等级")
    learn_times = models.IntegerField(default=0, verbose_name="学习时长(分钟)")
    students = models.IntegerField(default=0, verbose_name="学习人数")
    fav_nums = models.IntegerField(default=0, verbose_name="收藏人数")
    image = models.ImageField(max_length=100, upload_to="courses/%Y/%m/", verbose_name="封面图")
    click_nums = models.IntegerField(default=0, verbose_name="点击数")
    add_time = models.DateTimeField(default=datetime.now, verbose_name="添加时间")

    class Meta:
        verbose_name = "课程"
        verbose_name_plural = verbose_name


class Lesson(models.Model):
    course = models.ForeignKey(Courses, verbose_name="课程")
    name = models.CharField(max_length=100, verbose_name="章节名")
    add_time = models.DateTimeField(default=datetime.now, verbose_name="添加时间")

    class Meta:
        verbose_name = "章节"
        verbose_name_plural = verbose_name


class Video(models.Model):
    lesson = models.ForeignKey(Lesson, verbose_name="章节")
    name = models.CharField(max_length=100, verbose_name="章节名称")
    add_time = models.DateTimeField(default=datetime.now, verbose_name="添加时间")

    class Meta:
        verbose_name = "视频"
        verbose_name_plural = verbose_name


class CourseResourse(models.Model):
    course = models.ForeignKey(Courses, verbose_name="课程名")
    name = models.CharField(max_length=100, verbose_name="资源名称")
    download = models.FileField(upload_to="course/resource/%Y/%m", verbose_name="资源文件下载地址", max_length=100)
    add_time = models.DateTimeField(default=datetime.now, verbose_name="添加时间")

    class Meta:
        verbose_name = "课程资源"
        verbose_name_plural = verbose_name

[py]django课程模型

标签:高级   image   for   int   nts   资源   add   key   desc   

原文地址:https://www.cnblogs.com/iiiiiher/p/8379583.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!