zoukankan      html  css  js  c++  java
  • 第二节,Django+Xadmin打造上线标准的在线教育平台—创建课程app,在models.py文件生成4张表,课程表、课程章节表、课程视频表、课程资源表

    第二节,Django+Xadmin打造上线标准的在线教育平台—创建课程app,在models.py文件生成4张表,课程表、课程章节表、课程视频表、课程资源表

    创建名称为app_courses的课程APP,写数据库操作文件models.py

    models.py文件

    复制代码
    #!/usr/bin/env python
    # -*- coding:utf-8 -*-
    from __future__ import unicode_literals
    from datetime import datetime
    
    from django.db import models        # 导入models对象
    
    
    class Course(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(verbose_name='课程级别', choices=(('cj', '初级'), ('zj', '中级'), ('gj', '高级')), max_length=3)
        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(upload_to='courses/%Y/%m', verbose_name='课程封面图', max_length=100)
        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(Course,on_delete = models.CASCADE, verbose_name='外键课程表')      # 外键链表,外键连接Course表的主键,一对多关系
        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,on_delete = models.CASCADE, 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 CourseResource(models.Model):
        course = models.ForeignKey(Course,on_delete = models.CASCADE, 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
    复制代码

  • 相关阅读:
    C语言面试题大汇总
    cocos2d-x的win32编译环境
    完美解决Android SDK Manager无法更新
    ADT离线安装教程
    Android开发环境搭建教程
    如何利用dex2jar反编译APK
    Eclipse与Android源码中ProGuard工具的使用
    Proguard语法及常用proguard.cfg代码段
    Android之ProGuard混淆器
    Nutch源码阅读进程2---Generate
  • 原文地址:https://www.cnblogs.com/aooy/p/12022077.html
Copyright © 2011-2022 走看看