[py][mx]operation模型设计
用户表
UserMesasage 用户消息
UserFavorite 用户收藏
UserAsk 用户咨询
UserCourse 用户学习的课程
CourseComments 用户评论
收藏有3种类型
代码
from django.db import models
from datetime import datetime
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="姓名")
mobile = models.CharField(max_length=11, verbose_name="手机号")
course_name = models.CharField(max_length=50, verbose_name="课程名")
add_time = models.DateTimeField(default=datetime.now, verbose_name="添加时间")
class Meta:
verbose_name = "用户咨询"
verbose_name_plural = verbose_name
class CourseComments(models.Model):
user = models.ForeignKey(UserProfile, verbose_name="用户")
course = models.ForeignKey(Course, verbose_name="课程")
comments = models.CharField(max_length=200, verbose_name="评论")
add_time = models.DateTimeField(default=datetime.now, verbose_name="添加时间")
class Meta:
verbose_name = "课程评论"
verbose_name_plural = verbose_name
class UserFavorite(models.Model):
user = models.ForeignKey(UserProfile, verbose_name="用户")
course = models.ForeignKey(Course, verbose_name="用户")
# teacher = 可以用外键
# org =
# fav_type =
fav_id = models.IntegerField(default=0, verbose_name="数据id")
fav_type = models.IntegerField(choices=((1, "课程"), (2, "课程结构"), (3, "讲师"),), default=1, verbose_name="收藏类型")
add_time = models.DateTimeField(default=datetime.now, verbose_name="添加时间")
class Meta:
verbose_name = "用户收藏"
verbose_name_plural = verbose_name
class UserMessage(models.Model):
# 0表示发给所有用户, user = 非0, 发给某个用户的
user = models.IntegerField(default=0, verbose_name="接收用户")
message = models.CharField(max_length=500, verbose_name="消息内容")
has_read = models.BooleanField(default=False, verbose_name="是否已读")
add_time = models.DateTimeField(default=datetime.now, verbose_name="发送时间")
class Meta:
verbose_name = "用户消息"
verbose_name_plural = verbose_name
class UserCourse(models.Model):
user = models.ForeignKey(UserProfile, verbose_name="用户")
course = models.ForeignKey(Course, verbose_name="用户")
add_time = models.DateTimeField(default=datetime.now, verbose_name="添加时间")
class Meta:
verbose_name = "用户课程"
verbose_name_plural = verbose_name
我把他在思路上排了下前后
# 用户消息-用户收藏-咨询-学习的课程-评论
from users.models import UserProfile
from courses.models import Course
class UserMessage(models.Model):
# 0表示发给所有用户, user = 非0, 发给某个用户的
user = models.IntegerField(default=0, verbose_name="接收用户")
message = models.CharField(max_length=500, verbose_name="消息内容")
has_read = models.BooleanField(default=False, verbose_name="是否已读")
add_time = models.DateTimeField(default=datetime.now, verbose_name="发送时间")
class Meta:
verbose_name = "用户消息"
verbose_name_plural = verbose_name
class UserFavorite(models.Model):
user = models.ForeignKey(UserProfile, verbose_name="用户")
course = models.ForeignKey(Course, verbose_name="用户")
# teacher = 可以用外键
# org =
# fav_type =
fav_id = models.IntegerField(default=0, verbose_name="数据id")
fav_type = models.IntegerField(choices=((1, "课程"), (2, "课程结构"), (3, "讲师"),), default=1, verbose_name="收藏类型")
add_time = models.DateTimeField(default=datetime.now, verbose_name="添加时间")
class Meta:
verbose_name = "用户收藏"
verbose_name_plural = verbose_name
class UserAsk(models.Model):
name = models.CharField(max_length=20, verbose_name="姓名")
mobile = models.CharField(max_length=11, verbose_name="手机号")
course_name = models.CharField(max_length=50, verbose_name="课程名")
add_time = models.DateTimeField(default=datetime.now, verbose_name="添加时间")
class Meta:
verbose_name = "用户咨询"
verbose_name_plural = verbose_name
class UserCourse(models.Model):
user = models.ForeignKey(UserProfile, verbose_name="用户")
course = models.ForeignKey(Course, verbose_name="用户")
add_time = models.DateTimeField(default=datetime.now, verbose_name="添加时间")
class Meta:
verbose_name = "用户课程"
verbose_name_plural = verbose_name
class CourseComments(models.Model):
user = models.ForeignKey(UserProfile, verbose_name="用户")
course = models.ForeignKey(Course, verbose_name="课程")
comments = models.CharField(max_length=200, verbose_name="评论")
add_time = models.DateTimeField(default=datetime.now, verbose_name="添加时间")
class Meta:
verbose_name = "课程评论"
verbose_name_plural = verbose_name
至此小结
project
app
settings设置
zh-hans
tz
数据库不转
app创建
模型
1.user
userprofile
image
nick_name
gender
brith
mobile
address
banner
name
url
index
add_time
email
code
email
send_type
send_time
模型的
字段名显示
class Meta: 表名显示
class __str__: 给展示的字段
app名字显示
用户注册使用自定义表
settings设置
courses
课程-章节-视频
-课程资源附件
organization
城市-课程机构-教师
类比:app名-表名-字段名字
operation
operation(导入关系)
| |
UserProfile course organization
(按序)消息
收藏
咨询
学习
评论
用户消息(应该是谁发来的)
用户(外)(id=0和非0表示发给all,或某人)
消息
has_read
时间
收藏
用户(外)
课程(外)
fav_id(1,2,3)
fav_type(1:课程 2:培训机构 3:教师)
时间
咨询(可未登录)
用户name
手机
课程(外)
时间
学习课程
用户(外)
课程(外)
时间
评论
用户(外)
课程(外)
评论内容
时间