zoukankan      html  css  js  c++  java
  • Django打造在线教育平台_day_2:新建operation app 编写models

    1、新建operationapp,Tools 工具栏运行 run manage.py Task,输入:

    startapp operation

    2、分析operation app,需要建立表如下。

     

    3、编写operation/models.py

    from datetime import datetime
    
    from django.db import models
    
    from users.models import UserProfile
    from courses.models import Course
    
    # Create your models here.
    
    class UserAsk(models.Model):
        name = models.CharField(max_length=20, verbose_name=u'姓名')
        mobile = models.CharField(max_length=11, verbose_name=u'手机号')
        course_name = models.CharField(max_length=50, verbose_name=u'课程名')
        add_time = models.DateTimeField(default=datetime.now, verbose_name=u'添加时间')
    
        class Meta:
            verbose_name = u'用户咨询'
            verbose_name_plural = verbose_name
    
    
    class CourseComments(models.Model):
        """课程评论"""
        user = models.ForeignKey(UserProfile, verbose_name=u'用户')  # 引入外建,完成1对多的关系
        course = models.ForeignKey(Course, verbose_name=u'课程')
        comments = models.CharField(max_length=200, verbose_name=u'评论')
        add_time = models.DateTimeField(default=datetime.now, verbose_name=u'添加时间')
    
        class Meta:
            verbose_name = u'课程评论'
            verbose_name_plural = verbose_name
    
    class UserFavorite(models.Model):
        user = models.ForeignKey(UserProfile, verbose_name=u'用户')  # 引入外建,完成1对多的关系
        fav_id = models.IntegerField(default=0, verbose_name=u'数据id')
        fav_type = models.IntegerField(choices=((1,'课程'),(2,'课程机构'),(3,'讲师')), default=1, verbose_name=u'收藏类型')
        add_time = models.DateTimeField(default=datetime.now, verbose_name=u'添加时间')
    
        class Meta:
            verbose_name = u'用户收藏'
            verbose_name_plural = verbose_name
    
    class UserMessage(models.Model):
        user = models.IntegerField(default=0, verbose_name=u'接收用户') # default=id
        message = models.CharField(max_length=500, verbose_name=u'消息内容')
        has_read = models.BooleanField(default=False, verbose_name=u'是否已读') #默认未读
        add_time = models.DateTimeField(default=datetime.now, verbose_name=u'添加时间')
    
        class Meta:
            verbose_name = u'用户消息'
            verbose_name_plural = verbose_name
    
    
    class UserCourse(models.Model):
        user = models.ForeignKey(UserProfile, verbose_name=u'用户')  # 引入外建,完成1对多的关系
        course = models.ForeignKey(Course, verbose_name=u'课程')
        add_time = models.DateTimeField(default=datetime.now, verbose_name=u'添加时间')
    
        class Meta:
            verbose_name = u'用户课程'
            verbose_name_plural = verbose_name

    4、在MxOnline/settings.py中注册app

    INSTALLED_APPS = [
        'django.contrib.admin',
        'django.contrib.auth',
        'django.contrib.contenttypes',
        'django.contrib.sessions',
        'django.contrib.messages',
        'django.contrib.staticfiles',
        'users',  # 注册App
        'operation',
        'courses ',
        'organization ',
    ]

     5、在数据库生成新定义的表,Tools 工具栏运行 run manage.py Task输入:

    makemigrations 
    migrate 
  • 相关阅读:
    sass安装与使用
    前端兼容性问题
    springboot项目数据库错误记录
    C#实现微信聊天对话框
    关于html的多行匹配,正则re.S的使用(爬取豆瓣电影短评)
    判断网页能否打开?python
    利用python爬取点小图片,满足私欲(爬虫)
    ajax加载时的进度条
    java 发送微信客服消息
    Fastjson Mysql JDBC 反序列化
  • 原文地址:https://www.cnblogs.com/jp-mao/p/7070141.html
Copyright © 2011-2022 走看看