数据库设计(model分层设计)
标签:mysql python2.7 django1.9.8
APP分类
- Users-用户管理
创建用户models
# _*_ encoding:utf-8 _*_
# 用户基本信息表
from __future__ import unicode_literals
from django.db import models
from django.contrib.auth.models import AbstractUser
# Create your models here.
class UserProfile(AbstractUser):
nike_name = models.CharField(max_length=64, verbose_name=u'用户别名', default='')
birthday = models.DateField(verbose_name=u'生日', null=True, blank=True)
gender = models.CharField(max_length=32, choices=(('male', u'男'), ('female', '女')), default='')
address = models.CharField(max_length=128, verbose_name=u'地址', null=True, blank=True, default='')
mobile = models.CharField(max_length=11, verbose_name=u'手机号', null=True, blank=True, default='')
image = models.ImageField(upload_to='image/%Y/%m', default='image/default.png', max_length=128)
class Meta:
verbose_name = u'用户基本信息表'
verbose_name_plural = verbose_name
def __unicode__(self):
return self.username
基层邮箱验证和轮播图model放入用户基本信息表中
class EmailVerifyRecord(models.Model):
code = models.CharField(max_length=24, verbose_name=u'验证码')
email = models.EmailField(max_length=64, verbose_name=u'邮箱地址')
send_type = models.CharField(choices=(('register', u'注册'), ('forget', u'找回密码')), max_length=24, verbose_name=u'验证码方式')
send_time = models.DateTimeField(default=datetime.now, verbose_name=u'发送时间')
class Meta:
verbose_name = u'邮箱验证码发送'
verbose_name_plural = verbose_name
class Banner(models.Model):
title = models.CharField(max_length=128, verbose_name=u'标题')
image = models.ImageField(upload_to='banner/%Y/%m', verbose_name=u'图片地址', max_length=128)
url = models.URLField(max_length=128, verbose_name=u'连接地址')
index = models.IntegerField(default=100, verbose_name=u'轮播图顺序')
add_time = models.DateTimeField(default=datetime.now, verbose_name=u'添加时间')
class Meta:
verbose_name = u'轮播图'
verbose_name_plural = verbose_name
- Course-课程管理
课程基本信息 Cource
章节信息 Lesson
视频 Video
课程资源 CourceResource
model 创建
# _*_ encoding:utf-8 _*_
from __future__ import unicode_literals
from datetime import datetime
from django.db import models
# Create your models here.
class Course(models.Model):
name = models.CharField(max_length=128, verbose_name=u'课程名称')
desc = models.CharField(max_length=256, verbose_name=u'课程描述')
detail = models.TextField(verbose_name=u'课程详情')
degree = models.CharField(choices=(('cj', '初级'), ('zj', '中级'), ('gj', '高级')), max_length=2, verbose_name=u'课程难度')
learn_time = models.IntegerField(default=0, verbose_name=u'课程时长')
students = models.IntegerField(default=0, verbose_name=u'学习人数')
fav_nums = models.IntegerField(default=0, verbose_name=u'收藏人数')
click_nums = models.IntegerField(default=0, verbose_name=u'点击数')
image = models.ImageField(upload_to='courses/%Y/%m', verbose_name=u'封面图', max_length=128)
add_time = models.DateTimeField(default=datetime.now, 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=128, verbose_name=u'章节名称')
add_time = models.DateTimeField(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=128, 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(Course, verbose_name=u'资源')
download = models.FileField(upload_to='course/resource/%Y/%m', verbose_name=u'下载地址', max_length=128)
name = models.CharField(max_length=128, verbose_name=u'资源名称')
add_time = models.DateTimeField(default=datetime.now, verbose_name=u'添加时间')
class Meta:
verbose_name = u'资源信息'
verbose_name_plural = verbose_name
- Organization-机构和教师管理
CourseOrg - 课程机构基本信息
Teacher - 教师基本信息
CityDict - 城市信息
model 设计
# _*_ encoding:utf-8 _*_
from __future__ import unicode_literals
from datetime import datetime
from django.db import models
# Create your models here.
class CityDict(models.Model):
name = models.CharField(max_length=64, verbose_name=u'城市')
desc = models.CharField(max_length=256, verbose_name=u'城市描述')
add_time = models.DateTimeField(default=datetime.now, verbose_name=u'添加时间')
class Meta:
verbose_name = u'城市'
verbose_name_plural = verbose_name
class CourseOrg(models.Model):
name = models.CharField(max_length=64, verbose_name=u'机构名称')
desc = models.TextField(verbose_name=u'机构描述')
click_nums = models.IntegerField(default=0, verbose_name=u'点击数')
fav_nums = models.IntegerField(default=0, verbose_name=u'收藏数')
image = models.ImageField(upload_to='org/%Y/%m', max_length=128, verbose_name=u'图片地址')
address = models.CharField(max_length=64, verbose_name=u'地址')
city = models.ForeignKey(CityDict, verbose_name=u'城市')
add_time = models.DateTimeField(default=datetime.now, verbose_name=u'添加时间')
class Meta:
verbose_name = u'机构信息'
verbose_name_plural = verbose_name
class Teacher(models.Model):
org = models.ForeignKey(CourseOrg, verbose_name=u'教师')
name = models.CharField(max_length=64, verbose_name=u'教师名称')
points = models.CharField(max_length=32, verbose_name=u'授课特点')
work_years = models.IntegerField(default=0, verbose_name=u'工作年限')
work_company = models.CharField(max_length=32, verbose_name=u'工作公司')
work_position = models.CharField(max_length=32, verbose_name=u'工作职务')
click_nums = models.IntegerField(default=0, verbose_name=u'点击数')
fav_nums = models.IntegerField(default=0, verbose_name=u'收藏数')
add_time = models.DateTimeField(default=datetime.now, verbose_name=u'添加时间')
class Meta:
verbose_name = u'教师信息'
verbose_name_plural = verbose_name
- Operation-用户操作管理
UserAsk - 用户咨询
CourseComments - 用户评论
UserFavorite - 用户收藏
UserMessage - 用户消息
UserCourse - 用户学习的课程
models设计
# _*_ encoding:utf-8 _*_
from __future__ import unicode_literals
from datetime import datetime
from django.db import models
from users.models import UserProfile
from course.models import Course
# Create your models here.
class UserAsk(models.Model):
name = models.CharField(max_length=64, verbose_name=u'姓名')
mobile = models.CharField(max_length=11, verbose_name=u'手机号')
course_name = models.CharField(max_length=64, 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'用户')
course = models.ForeignKey(Course, verbose_name=u'课程')
comments = models.CharField(max_length=256, 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'用户')
fav_id = models.IntegerField(default=0, verbose_name=u'收藏内容类型')
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'接受用户')
message = models.CharField(max_length=512, 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'用户')
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
- app集合
将所有的app放入一个apps集合中
setting.py
import sys
# model serach
sys.path.insert(0, os.path.join(BASE_DIR, 'apps'))
- 本篇博客原视频博主[慕课在线教育平台]
- 本篇博客撰写人: XiaoJinZi 转载请注明出处
- 学生能力有限 附上邮箱: [email protected] 不足以及误处请大佬指责