用户操作
- UserAsk 用户咨询
from apps.users.models import BaseModel
class UserAsk(BaseModel):
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='课程名')
class Meta:
verbose_name = '用户咨询'
verbose_name_plural = verbose_name
- CourseComments 课程评论
from django.db import models
from django.contrib.auth import get_user_model
from apps.users.models import BaseModel
from apps.courses.models import Course
# 从settings里面直接获取user,不用导入我们自己定义的UserProfile(因为有的时候我们需要使用到django自带的user管理)
UserProfile = get_user_model()
class CourseComments(BaseModel):
user = models.ForeignKey(UserProfile, verbose_name='用户')
course = models.ForeignKey(Course, verbose_name='课程')
comments = models.CharField(max_length=200, verbose_name='评论内容')
class Meta:
verbose_name = '课程评论'
verbose_name_plural = verbose_name
- UserFavorite 用户收藏
class UserFavorite(BaseModel):
user = models.ForeignKey(UserProfile, verbose_name='用户')
# 不使用以下两种方式,因为系统会变大,类型会变多,类也会越来越多,会导致太多的外键,还会需要造成修改表结构,新增一个类型就得新增一列
# course = models.ForeignKey(Course, verbose_name='课程')
# teacher = models.ForeignKey(Teacher, verbose_name='讲师')
fav_id = models.IntegerField(verbose_name='数据id')
fav_tag = models.IntegerField(choices=(('1', '课程'), ('2', '课程机构'), ('3', '讲师')), default=1, verbose_name='收藏类型')
class Meta:
verbose_name = '用户收藏'
verbose_name_plural = verbose_name
- UserMessage 用户消息
数据有是否已读的状态
class UserMessage(BaseModel):
user = models.ForeignKey(UserProfile, verbose_name='用户')
message = models.CharField(max_length=200, verbose_name='内容')
has_read = models.BooleanField(default=False, verbose_name='是否已读')
class Meta:
verbose_name = '用户消息'
verbose_name_plural = verbose_name
- UserCourse 我的课程
一个课程可以被多个用户学习,这个是一对多的关系。
从另一个角度来讲,一个用户可以学习多门课程,这个是多对多的关系。
先设计成一对多的关系,后期再改。
class UserCourse(BaseModel):
# 有两个外键 user 和 course
user = models.ForeignKey(UserProfile, verbose_name='用户')
course = models.ForeignKey(Course, verbose_name='课程')
class Meta:
verbose_name = '用户课程'
verbose_name_plural = verbose_name
完整的用户操作model
之前上面没添加on_delete=models.CASCADE,以下面的完整的版本为准
from django.db import models
from django.contrib.auth import get_user_model
from apps.users.models import BaseModel
from apps.courses.models import Course
# 从settings里面直接获取user,不用导入我们自己定义的UserProfile(因为有的时候我们需要使用到django自带的user管理)
UserProfile = get_user_model()
class UserAsk(BaseModel):
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='课程名')
class Meta:
verbose_name = '用户咨询'
verbose_name_plural = verbose_name
class CourseComments(BaseModel):
user = models.ForeignKey(UserProfile, on_delete=models.CASCADE, verbose_name='用户')
course = models.ForeignKey(Course, on_delete=models.CASCADE, verbose_name='课程')
comments = models.CharField(max_length=200, verbose_name='评论内容')
class Meta:
verbose_name = '课程评论'
verbose_name_plural = verbose_name
class UserFavorite(BaseModel):
user = models.ForeignKey(UserProfile, on_delete=models.CASCADE, verbose_name='用户')
# 不使用以下两种方式,因为系统会变大,类型会变多,类也会越来越多,会导致太多的外键,还会需要造成修改表结构,新增一个类型就得新增一列
# course = models.ForeignKey(Course, verbose_name='课程')
# teacher = models.ForeignKey(Teacher, verbose_name='讲师')
fav_id = models.IntegerField(verbose_name='数据id')
fav_tag = models.IntegerField(choices=(('1', '课程'), ('2', '课程机构'), ('3', '讲师')), default=1, verbose_name='收藏类型')
class Meta:
verbose_name = '用户收藏'
verbose_name_plural = verbose_name
class UserMessage(BaseModel):
user = models.ForeignKey(UserProfile, on_delete=models.CASCADE, verbose_name='用户')
message = models.CharField(max_length=200, verbose_name='内容')
has_read = models.BooleanField(default=False, verbose_name='是否已读')
class Meta:
verbose_name = '用户消息'
verbose_name_plural = verbose_name
class UserCourse(BaseModel):
# 有两个外键 user 和 course
user = models.ForeignKey(UserProfile, on_delete=models.CASCADE, verbose_name='用户')
course = models.ForeignKey(Course, on_delete=models.CASCADE, verbose_name='课程')
class Meta:
verbose_name = '用户课程'
verbose_name_plural = verbose_name
**粗体** _斜体_ [链接](http://example.com) `代码` - 列表 > 引用
。你还可以使用@
来通知其他用户。