首页 > 其他分享 >012双写一致性之定时更新,异步发送短信,异步秒杀逻辑前后端,课程页面前端,课程相关表分析,基于对象跨表查询和双下划綫连表查询,课程表数据录入,课程主页接口

012双写一致性之定时更新,异步发送短信,异步秒杀逻辑前后端,课程页面前端,课程相关表分析,基于对象跨表查询和双下划綫连表查询,课程表数据录入,课程主页接口

时间:2023-07-04 21:24:27浏览次数:52  
标签:异步 14 查询 course 课程 2022 time id 07

0 双写一致性之定时更新

# 一旦加入缓存,就会出现数据不一致的请请求
# 双写一致性问题
	-1 改数据,删缓存
    -2 改数据,改缓存
    -3 定时更新
    
    
# 首页轮播图存在双写一致性问题这个问题
	-以现在的技术水平(信号),做不到 :改数据删缓存
	-能选择的就是定时更新
    	-轮播图接口---》实时性要求没有那么高
        
        
        
# celery的定时任务
	-定时更新轮播图

0 异步发送短信

# 视图函数
@action(methods=['GET'], detail=False)
def send_sms(self, request, *args, **kwargs):
    mobile = request.query_params.get('mobile', None)
    code = get_code()  # 把code存起来,放到缓存中,目前在内存,后期换别的
    cache.set('send_sms_code_%s' % mobile, code)
    if mobile:
        # 开启一个线程,执行发送短信
        # t = Thread(target=send_sms_by_mobile, args=[mobile, code])
        # t.start()
        # 提交异步任务---》异步发送
        res = send_sms.delay(mobile,code)
        print(res)
        return APIResponse(msg='短信已发送')
    raise APIException('手机号没有携带')

# 任务
from libs.send_tx_sms import send_sms_by_mobile
@app.task
def send_sms(mobile, code):
    res=send_sms_by_mobile(mobile,code)
    if res:
        return '%s的短信发送成功,验证码是%s'%(mobile,code)
    else:
        return '%s的短信发送失败'%mobile

1 异步秒杀逻辑前后端

1.1 前端 Sckill.vue

<template>
  <div>
    <h2>go语言从入门到放弃</h2>
    <el-button type="danger" @click="handleSckill">秒杀</el-button>

  </div>
</template>

<script>
export default {
  name: "Sckill",
  data() {
    return {
      t: null,
      task_id: '',
    }
  },
  methods: {
    handleSckill() {
      this.$axios.post(`${this.$settings.BASE_URL}user/sckill/`, {
        name: "性感帽子",
      }).then(res => {
        if (res.data.code == 100) {
          alert('您正在排队')
          this.task_id = res.data.task_id
          // 起个转圈的东西
          // 起定时任务
          this.t = setInterval(() => {
            this.$axios.get(`${this.$settings.BASE_URL}user/sckill/?task_id=${this.task_id}`).then(res => {
              if (res.data.code == 100 || res.data.code == 101) {
                this.$message(res.data.msg)
                //销毁定时器
                clearInterval(this.t)
                this.t = null
              } else {
                console.log('过会再查')
              }
            })
          }, 3000)
        }
      })
    }
  }
}
</script>

<style scoped>

</style>

1.2 后端

视图类

from celery_task.user_task import sckill_goods
from celery_task.celery import app
from celery.result import AsyncResult


class SckillView(APIView):
    def post(self, request, *args, **kwargs):
        name = request.data.get('name')
        # 提交秒杀异步任务
        res = sckill_goods.delay(name)
        return APIResponse(task_id=str(res))

    def get(self, request, *args, **kwargs):
        task_id = request.GET.get('task_id')
        a = AsyncResult(id=task_id, app=app)
        if a.successful():  # 正常执行完成
            result = a.get()  # 任务返回的结果
            if result:
                return APIResponse(code=100, msg='秒杀成功')
            else:
                return APIResponse(code=101, msg='秒杀失败')
        elif a.status == 'STARTED':
            print('任务已经开始被执行')
            return APIResponse(code=103, msg='还在排队')
        else:
            return APIResponse(code=102, msg='没成功')

路由

urlpatterns = [
    path('sckill/', SckillView.as_view()),
]

任务

@app.task
def sckill_goods(name):
    # 逻辑是:开启事务---》扣减库存---》生成订单
    import time
    time.sleep(6)
    res = random.choice([100, 102])
    if res == 100:
        print('%s被秒杀成功了' % name)
        return True
    else:
        print('%s被秒杀失败了' % name)
        return False

image

2 课程页页面前端

#1 前端  新建三个组件
	LightCourse.vue
    FreeCourse.vue
    ActualCourse.vue
    
# 2 配置路由
	import FreeCourse from "@/views/FreeCourse";
    import ActualCourse from "@/views/ActualCourse";
    import LightCourse from "@/views/LightCourse";
    
     {
        path: '/free-course',
        name: 'free-course',
        component: FreeCourse
    },
    {
        path: '/actual-course',
        name: 'actual-course',
        component: ActualCourse
    },
    {
        path: '/light-course',
        name: 'light-course',
        component: LightCourse
    },

# 3 FreeCourse.vue
<template>
  <div class="course">
    <Header></Header>
    <div class="main">
      <!-- 筛选条件 -->
      <div class="condition">
        <ul class="cate-list">
          <li class="title">课程分类:</li>
          <li class="this">全部</li>
          <li>Python</li>
          <li>Linux运维</li>
          <li>Python进阶</li>
          <li>开发工具</li>
          <li>Go语言</li>
          <li>机器学习</li>
          <li>技术生涯</li>
        </ul>

        <div class="ordering">
          <ul>
            <li class="title">筛&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;选:</li>
            <li class="default this">默认</li>
            <li class="hot">人气</li>
            <li class="price">价格</li>
          </ul>
          <p class="condition-result">共21个课程</p>
        </div>

      </div>
      <!-- 课程列表 -->
      <div class="course-list">
        <div class="course-item">
          <div class="course-image">
            <img src="@/assets/img/course-cover.jpeg" alt="">
          </div>
          <div class="course-info">
            <h3>Python开发21天入门 <span><img src="@/assets/img/avatar1.svg" alt="">100人已加入学习</span></h3>
            <p class="teather-info">Alex 金角大王 老男孩Python教学总监 <span>共154课时/更新完成</span></p>
            <ul class="lesson-list">
              <li><span class="lesson-title">01 | 第1节:初识编码</span> <span class="free">免费</span></li>
              <li><span class="lesson-title">01 | 第1节:初识编码初识编码</span> <span class="free">免费</span></li>
              <li><span class="lesson-title">01 | 第1节:初识编码</span></li>
              <li><span class="lesson-title">01 | 第1节:初识编码初识编码</span></li>
            </ul>
            <div class="pay-box">
              <span class="discount-type">限时免费</span>
              <span class="discount-price">¥6.00元</span>
              <span class="original-price">原价:9.00元</span>
              <span class="buy-now">立即购买</span>
            </div>
          </div>
        </div>
        <div class="course-item">
          <div class="course-image">
            <img src="@/assets/img/course-cover.jpeg" alt="">
          </div>
          <div class="course-info">
            <h3>Python开发21天入门 <span><img src="@/assets/img/avatar1.svg" alt="">100人已加入学习</span></h3>
            <p class="teather-info">Alex 金角大王 老男孩Python教学总监 <span>共154课时/更新完成</span></p>
            <ul class="lesson-list">
              <li><span class="lesson-title">01 | 第1节:初识编码</span> <span class="free">免费</span></li>
              <li><span class="lesson-title">01 | 第1节:初识编码初识编码</span> <span class="free">免费</span></li>
              <li><span class="lesson-title">01 | 第1节:初识编码</span></li>
              <li><span class="lesson-title">01 | 第1节:初识编码初识编码</span></li>
            </ul>
            <div class="pay-box">
              <span class="discount-type">限时免费</span>
              <span class="discount-price">¥0.00元</span>
              <span class="original-price">原价:9.00元</span>
              <span class="buy-now">立即购买</span>
            </div>
          </div>
        </div>
        <div class="course-item">
          <div class="course-image">
            <img src="@/assets/img/course-cover.jpeg" alt="">
          </div>
          <div class="course-info">
            <h3>Python开发21天入门 <span><img src="@/assets/img/avatar1.svg" alt="">100人已加入学习</span></h3>
            <p class="teather-info">Alex 金角大王 老男孩Python教学总监 <span>共154课时/更新完成</span></p>
            <ul class="lesson-list">
              <li><span class="lesson-title">01 | 第1节:初识编码</span> <span class="free">免费</span></li>
              <li><span class="lesson-title">01 | 第1节:初识编码初识编码</span> <span class="free">免费</span></li>
              <li><span class="lesson-title">01 | 第1节:初识编码</span></li>
              <li><span class="lesson-title">01 | 第1节:初识编码初识编码</span></li>
            </ul>
            <div class="pay-box">
              <span class="discount-type">限时免费</span>
              <span class="discount-price">¥0.00元</span>
              <span class="original-price">原价:9.00元</span>
              <span class="buy-now">立即购买</span>
            </div>
          </div>
        </div>
        <div class="course-item">
          <div class="course-image">
            <img src="@/assets/img/course-cover.jpeg" alt="">
          </div>
          <div class="course-info">
            <h3>Python开发21天入门 <span><img src="@/assets/img/avatar1.svg" alt="">100人已加入学习</span></h3>
            <p class="teather-info">Alex 金角大王 老男孩Python教学总监 <span>共154课时/更新完成</span></p>
            <ul class="lesson-list">
              <li><span class="lesson-title">01 | 第1节:初识编码</span> <span class="free">免费</span></li>
              <li><span class="lesson-title">01 | 第1节:初识编码初识编码</span> <span class="free">免费</span></li>
              <li><span class="lesson-title">01 | 第1节:初识编码</span></li>
              <li><span class="lesson-title">01 | 第1节:初识编码初识编码</span></li>
            </ul>
            <div class="pay-box">
              <span class="discount-type">限时免费</span>
              <span class="discount-price">¥0.00元</span>
              <span class="original-price">原价:9.00元</span>
              <span class="buy-now">立即购买</span>
            </div>
          </div>
        </div>
      </div>
    </div>
    <Footer></Footer>
  </div>
</template>

<script>
import Header from "@/components/Header"
import Footer from "@/components/Footer"

export default {
  name: "Course",
  data() {
    return {
      category: 0,
    }
  },
  components: {
    Header,
    Footer,
  }
}
</script>

<style scoped>
.course {
  background: #f6f6f6;
}

.course .main {
  width: 1100px;
  margin: 35px auto 0;
}

.course .condition {
  margin-bottom: 35px;
  padding: 25px 30px 25px 20px;
  background: #fff;
  border-radius: 4px;
  box-shadow: 0 2px 4px 0 #f0f0f0;
}

.course .cate-list {
  border-bottom: 1px solid #333;
  border-bottom-color: rgba(51, 51, 51, .05);
  padding-bottom: 18px;
  margin-bottom: 17px;
}

.course .cate-list::after {
  content: "";
  display: block;
  clear: both;
}

.course .cate-list li {
  float: left;
  font-size: 16px;
  padding: 6px 15px;
  line-height: 16px;
  margin-left: 14px;
  position: relative;
  transition: all .3s ease;
  cursor: pointer;
  color: #4a4a4a;
  border: 1px solid transparent; /* transparent 透明 */
}

.course .cate-list .title {
  color: #888;
  margin-left: 0;
  letter-spacing: .36px;
  padding: 0;
  line-height: 28px;
}

.course .cate-list .this {
  color: #ffc210;
  border: 1px solid #ffc210 !important;
  border-radius: 30px;
}

.course .ordering::after {
  content: "";
  display: block;
  clear: both;
}

.course .ordering ul {
  float: left;
}

.course .ordering ul::after {
  content: "";
  display: block;
  clear: both;
}

.course .ordering .condition-result {
  float: right;
  font-size: 14px;
  color: #9b9b9b;
  line-height: 28px;
}

.course .ordering ul li {
  float: left;
  padding: 6px 15px;
  line-height: 16px;
  margin-left: 14px;
  position: relative;
  transition: all .3s ease;
  cursor: pointer;
  color: #4a4a4a;
}

.course .ordering .title {
  font-size: 16px;
  color: #888;
  letter-spacing: .36px;
  margin-left: 0;
  padding: 0;
  line-height: 28px;
}

.course .ordering .this {
  color: #ffc210;
}

.course .ordering .price {
  position: relative;
}

.course .ordering .price::before,
.course .ordering .price::after {
  cursor: pointer;
  content: "";
  display: block;
  width: 0px;
  height: 0px;
  border: 5px solid transparent;
  position: absolute;
  right: 0;
}

.course .ordering .price::before {
  border-bottom: 5px solid #aaa;
  margin-bottom: 2px;
  top: 2px;
}

.course .ordering .price::after {
  border-top: 5px solid #aaa;
  bottom: 2px;
}

.course .course-item:hover {
  box-shadow: 4px 6px 16px rgba(0, 0, 0, .5);
}

.course .course-item {
  width: 1100px;
  background: #fff;
  padding: 20px 30px 20px 20px;
  margin-bottom: 35px;
  border-radius: 2px;
  cursor: pointer;
  box-shadow: 2px 3px 16px rgba(0, 0, 0, .1);
  /* css3.0 过渡动画 hover 事件操作 */
  transition: all .2s ease;
}

.course .course-item::after {
  content: "";
  display: block;
  clear: both;
}

/* 顶级元素 父级元素  当前元素{} */
.course .course-item .course-image {
  float: left;
  width: 423px;
  height: 210px;
  margin-right: 30px;
}

.course .course-item .course-image img {
  width: 100%;
}

.course .course-item .course-info {
  float: left;
  width: 596px;
}

.course-item .course-info h3 {
  font-size: 26px;
  color: #333;
  font-weight: normal;
  margin-bottom: 8px;
}

.course-item .course-info h3 span {
  font-size: 14px;
  color: #9b9b9b;
  float: right;
  margin-top: 14px;
}

.course-item .course-info h3 span img {
  width: 11px;
  height: auto;
  margin-right: 7px;
}

.course-item .course-info .teather-info {
  font-size: 14px;
  color: #9b9b9b;
  margin-bottom: 14px;
  padding-bottom: 14px;
  border-bottom: 1px solid #333;
  border-bottom-color: rgba(51, 51, 51, .05);
}

.course-item .course-info .teather-info span {
  float: right;
}

.course-item .lesson-list::after {
  content: "";
  display: block;
  clear: both;
}

.course-item .lesson-list li {
  float: left;
  width: 44%;
  font-size: 14px;
  color: #666;
  padding-left: 22px;
  /* background: url("路径") 是否平铺 x轴位置 y轴位置 */
  background: url("/src/assets/img/play-icon-gray.svg") no-repeat left 4px;
  margin-bottom: 15px;
}

.course-item .lesson-list li .lesson-title {
  /* 以下3句,文本内容过多,会自动隐藏,并显示省略符号 */
  text-overflow: ellipsis;
  overflow: hidden;
  white-space: nowrap;
  display: inline-block;
  max-width: 200px;
}

.course-item .lesson-list li:hover {
  background-image: url("/src/assets/img/play-icon-yellow.svg");
  color: #ffc210;
}

.course-item .lesson-list li .free {
  width: 34px;
  height: 20px;
  color: #fd7b4d;
  vertical-align: super;
  margin-left: 10px;
  border: 1px solid #fd7b4d;
  border-radius: 2px;
  text-align: center;
  font-size: 13px;
  white-space: nowrap;
}

.course-item .lesson-list li:hover .free {
  color: #ffc210;
  border-color: #ffc210;
}

.course-item .pay-box::after {
  content: "";
  display: block;
  clear: both;
}

.course-item .pay-box .discount-type {
  padding: 6px 10px;
  font-size: 16px;
  color: #fff;
  text-align: center;
  margin-right: 8px;
  background: #fa6240;
  border: 1px solid #fa6240;
  border-radius: 10px 0 10px 0;
  float: left;
}

.course-item .pay-box .discount-price {
  font-size: 24px;
  color: #fa6240;
  float: left;
}

.course-item .pay-box .original-price {
  text-decoration: line-through;
  font-size: 14px;
  color: #9b9b9b;
  margin-left: 10px;
  float: left;
  margin-top: 10px;
}

.course-item .pay-box .buy-now {
  width: 120px;
  height: 38px;
  background: transparent;
  color: #fa6240;
  font-size: 16px;
  border: 1px solid #fd7b4d;
  border-radius: 3px;
  transition: all .2s ease-in-out;
  float: right;
  text-align: center;
  line-height: 38px;
}

.course-item .pay-box .buy-now:hover {
  color: #fff;
  background: #ffc210;
  border: 1px solid #ffc210;
}
</style>

3 课程相关表分析

# 表分析
	-课程分类表:id,分类名,继承BaseModel
    	-跟课程表是一对多,一个分类下有很多课程
    -课程表(实战课课表)
    	-如果一个表:
        	-不同课程直接,字段可能不一样
        -多个课程,多个表
        	-只写实战课这条线
    -章节表:
    	跟课程是一对多
    -课时表
    	跟章节是一对多
    -老师表
    	-跟课程一对多
        
        
        
# 表的关联关系---》公司中外键都是逻辑外键,不建物理外键
	-靠一个东西建立出来的三种关系----》外键
        -一对一 
        -一对多
        -多对多
        
        图书  作者 多对多
        图书表
        id  name   price
        1    xx     33
        2    yy     32
        
        作者
       id  name       addr
        1    多对     上海
        2    大师傅     北京
        
        中间表
        id  book_id   auth_id
        1   1            1
        2   1            2
        3   2            1
    	

3.1 基于对象跨表查询和双下划綫连表查询

#基于对象的跨表查询:
'''
-正:字段        
-反:表名小写(一对一是  表名小写,一对多   表名小写_set.all())
-related_name='coursechapters'   基于对象跨表查反向查询,替换表名小写
'''

#基于双下划线的连表查询:
'''
正:字段    
反:表名小写
-related_query_name='xxx'     基于连表查反向查询,替换表名小写
'''

4 课程表数据录入

# 把sql执行
# 把 media文件夹下的图片放到对应位置

INSERT INTO luffy_teacher(id, orders, is_show, is_delete, created_time, updated_time, name, role, title, signature, image, brief) VALUES (1, 1, 1, 0, '2022-07-14 13:44:19.661327', '2022-07-14 13:46:54.246271', 'Alex', 1, '老男孩Python教学总监', '金角大王', 'teacher/alex_icon.png', '老男孩教育CTO & CO-FOUNDER 国内知名PYTHON语言推广者 51CTO学院2016\2017年度最受学员喜爱10大讲师之一 多款开源软件作者 曾任职公安部、飞信、中金公司、NOKIA中国研究院、华尔街英语、ADVENT、汽车之家等公司');

INSERT INTO luffy_teacher(id, orders, is_show, is_delete, created_time, updated_time, name, role, title, signature, image, brief) VALUES (2, 2, 1, 0, '2022-07-14 13:45:25.092902', '2022-07-14 13:45:25.092936', 'Mjj', 0, '前美团前端项目组架构师', NULL, 'teacher/mjj_icon.png', '是马JJ老师, 一个集美貌与才华于一身的男人,搞过几年IOS,又转了前端开发几年,曾就职于美团网任高级前端开发,后来因为不同意王兴(美团老板)的战略布局而出家做老师去了,有丰富的教学经验,开起车来也毫不含糊。一直专注在前端的前沿技术领域。同时,爱好抽烟、喝酒、烫头(锡纸烫)。 我的最爱是前端,因为前端妹子多。');

INSERT INTO luffy_teacher(id, orders, is_show, is_delete, created_time, updated_time, name, role, title, signature, image, brief) VALUES (3, 3, 1, 0, '2022-07-14 13:46:21.997846', '2022-07-14 13:46:21.997880', 'Lyy', 0, '老男孩Linux学科带头人', NULL, 'teacher/lyy_icon.png', 'Linux运维技术专家,老男孩Linux金牌讲师,讲课风趣幽默、深入浅出、声音洪亮到爆炸');


-- 分类表
INSERT INTO luffy_course_category(id, orders, is_show, is_delete, created_time, updated_time, name) VALUES (1, 1, 1, 0, '2022-07-14 13:40:58.690413', '2022-07-14 13:40:58.690477', 'Python');

INSERT INTO luffy_course_category(id, orders, is_show, is_delete, created_time, updated_time, name) VALUES (2, 2, 1, 0, '2022-07-14 13:41:08.249735', '2022-07-14 13:41:08.249817', 'Linux');


-- 课程表
INSERT INTO luffy_course(id, orders, is_show, is_delete, created_time, updated_time, name, course_img, course_type, brief, level, pub_date, period, attachment_path, status, students, sections, pub_sections, price, course_category_id, teacher_id) VALUES (1, 1, 1, 0, '2022-07-14 13:54:33.095201', '2022-07-14 13:54:33.095238', 'Python开发21天入门', 'courses/alex_python.png', 0, 'Python从入门到入土&&&Python从入门到入土&&&Python从入门到入土&&&Python从入门到入土&&&Python从入门到入土&&&Python从入门到入土&&&Python从入门到入土&&&Python从入门到入土&&&Python从入门到入土&&&Python从入门到入土&&&Python从入门到入土&&&Python从入门到入土', 0, '2022-07-14', 21, '', 0, 231, 120, 120, 0.00, 1, 1);

INSERT INTO luffy_course(id, orders, is_show, is_delete, created_time, updated_time, name, course_img, course_type, brief, level, pub_date, period, attachment_path, status, students, sections, pub_sections, price, course_category_id, teacher_id) VALUES (2, 2, 1, 0, '2022-07-14 13:56:05.051103', '2022-07-14 13:56:05.051142', 'Python项目实战', 'courses/mjj_python.png', 0, '', 1, '2022-07-14', 30, '', 0, 340, 120, 120, 99.00, 1, 2);

INSERT INTO luffy_course(id, orders, is_show, is_delete, created_time, updated_time, name, course_img, course_type, brief, level, pub_date, period, attachment_path, status, students, sections, pub_sections, price, course_category_id, teacher_id) VALUES (3, 3, 1, 0, '2022-07-14 13:57:21.190053', '2022-07-14 13:57:21.190095', 'Linux系统基础5周入门精讲', 'courses/lyy_linux.png', 0, '', 0, '2022-07-14', 25, '', 0, 219, 100, 100, 39.00, 2, 3);


-- 章节表
INSERT INTO luffy_course_chapter(id, orders, is_show, is_delete, created_time, updated_time, chapter, name, summary, pub_date, course_id) VALUES (1, 1, 1, 0, '2022-07-14 13:58:34.867005', '2022-07-14 14:00:58.276541', 1, '计算机原理', '', '2022-07-14', 1);

INSERT INTO luffy_course_chapter(id, orders, is_show, is_delete, created_time, updated_time, chapter, name, summary, pub_date, course_id) VALUES (2, 2, 1, 0, '2022-07-14 13:58:48.051543', '2022-07-14 14:01:22.024206', 2, '环境搭建', '', '2022-07-14', 1);

INSERT INTO luffy_course_chapter(id, orders, is_show, is_delete, created_time, updated_time, chapter, name, summary, pub_date, course_id) VALUES (3, 3, 1, 0, '2022-07-14 13:59:09.878183', '2022-07-14 14:01:40.048608', 1, '项目创建', '', '2022-07-14', 2);

INSERT INTO luffy_course_chapter(id, orders, is_show, is_delete, created_time, updated_time, chapter, name, summary, pub_date, course_id) VALUES (4, 4, 1, 0, '2022-07-14 13:59:37.448626', '2022-07-14 14:01:58.709652', 1, 'Linux环境创建', '', '2022-07-14', 3);


-- 课时表
INSERT INTO luffy_course_Section(id, is_show, is_delete, created_time, updated_time, name, orders, section_type, section_link, duration, pub_date, free_trail, chapter_id) VALUES (1, 1, 0, '2022-07-14 14:02:33.779098', '2022-07-14 14:02:33.779135', '计算机原理上', 1, 2, NULL, NULL, '2022-07-14 14:02:33.779193', 1, 1);

INSERT INTO luffy_course_Section(id, is_show, is_delete, created_time, updated_time, name, orders, section_type, section_link, duration, pub_date, free_trail, chapter_id) VALUES (2, 1, 0, '2022-07-14 14:02:56.657134', '2022-07-14 14:02:56.657173', '计算机原理下', 2, 2, NULL, NULL, '2022-07-14 14:02:56.657227', 1, 1);

INSERT INTO luffy_course_Section(id, is_show, is_delete, created_time, updated_time, name, orders, section_type, section_link, duration, pub_date, free_trail, chapter_id) VALUES (3, 1, 0, '2022-07-14 14:03:20.493324', '2022-07-14 14:03:52.329394', '环境搭建上', 1, 2, NULL, NULL, '2022-07-14 14:03:20.493420', 0, 2);

INSERT INTO luffy_course_Section(id, is_show, is_delete, created_time, updated_time, name, orders, section_type, section_link, duration, pub_date, free_trail, chapter_id) VALUES (4, 1, 0, '2022-07-14 14:03:36.472742', '2022-07-14 14:03:36.472779', '环境搭建下', 2, 2, NULL, NULL, '2022-07-14 14:03:36.472831', 0, 2);

INSERT INTO luffy_course_Section(id, is_show, is_delete, created_time, updated_time, name, orders, section_type, section_link, duration, pub_date, free_trail, chapter_id) VALUES (5, 1, 0, '2022-07-14 14:04:19.338153', '2022-07-14 14:04:19.338192', 'web项目的创建', 1, 2, NULL, NULL, '2022-07-14 14:04:19.338252', 1, 3);

INSERT INTO luffy_course_Section(id, is_show, is_delete, created_time, updated_time, name, orders, section_type, section_link, duration, pub_date, free_trail, chapter_id) VALUES (6, 1, 0, '2022-07-14 14:04:52.895855', '2022-07-14 14:04:52.895890', 'Linux的环境搭建', 1, 2, NULL, NULL, '2022-07-14 14:04:52.895942', 1, 4);

5 课程主页接口

# 课程分类接口

# 查询所有课程接口
	-带过滤
    -带排序
    -带分页

视图类

from .models import CourseCategory
from rest_framework.viewsets import GenericViewSet
from rest_framework.mixins import ListModelMixin
from .serializer import CourseCategorySerializer
from utils.common_mixin import CommonListModelMixin as ListModelMixin

class CourseCategoryView(GenericViewSet, ListModelMixin):
    # 查询所有
    queryset = CourseCategory.objects.filter(is_delete=False, is_show=True).order_by('orders')
    serializer_class = CourseCategorySerializer

序列化类

class CourseCategorySerializer(serializers.ModelSerializer):
    class Meta:
        model = CourseCategory
        fields = ['id','name']

路由

from django.contrib import admin
from django.urls import path

from rest_framework.routers import SimpleRouter

router = SimpleRouter()
from .views import CourseCategoryView

router.register('category', CourseCategoryView, 'category')
urlpatterns = [

]
urlpatterns += router.urls

标签:异步,14,查询,course,课程,2022,time,id,07
From: https://www.cnblogs.com/whxx/p/17527050.html

相关文章

  • 013查询所有课程接口,课程详情接口,课程详情后台之所有章节接口,所有课程前台,课程详情前
    1查询所有课程接口#查询所有课程接口 -带过滤:按分类过滤-带排序:价格,学习人数-带分页:简单分页1.1视图类classCourseView(GenericViewSet,ListModelMixin):queryset=Course.objects.filter(is_delete=False,is_show=True).order_by('orders')seria......
  • 【本周特惠课程】深度学习6大模型部署场景(Pytorch+NCNN+MNN+Tengine+TensorRT+微信小
    前言欢迎大家关注有三AI的视频课程系列,我们的视频课程系列共分为5层境界,内容和学习路线图如下:第1层:掌握学习算法必要的预备知识,包括Python编程,深度学习基础,数据使用,框架使用。第2层:掌握CV算法最底层的能力,包括模型设计基础,图像分类,模型分析。第3层:掌握CV算法最核心的方向,包括图像分......
  • .Net下验证MongoDB 的 Linq 模式联合查询是否可用
    MongoDB.Driver类库提供了Linq查询的支持。然而,在使用Linq进行联合查询时,是否能够正确转换为MongoDB底层的查询语句还有待验证。今天,我将进行实验来验证一下。输出查询语句首先,通过订阅MongoClientSettings的功能,将查询语句输出。varsettings=MongoCli......
  • 记录XPO查询 日志
    记录由XPO产生和执行的sql语句//z2013-02-2714:01:[email protected][T215,L2906,R88,V3140]1.在App.Config中添加如下行:[XML]<?xmlversion="1.0"encoding="utf-8"?><configuration><system.diagnostics><switches&......
  • SQL Server 查询数据表字段及字段注释
    SELECTCASEWHENcol.colorder=1THENobj.nameELSE''ENDAS表名,col.colorderAS序号,col.nameAS列名,ISNULL(ep.[value],'')AS列说明,t.nameAS数据类型,col.lengthAS长度,ISNULL(COLUMNPROPERTY(col.id,col.name,'Scale'),0)AS小数位数......
  • fastadmin对查询结果集进行分页
    //$arr=array();//if(!empty($arr)){//foreach($arras$key=>$value){//foreach($value['productList']as$k=>$v){//$list[]=$v;......
  • SQLServer中查询表结构(表主键 、列说明、列数据类型、所有表名)的Sql语句
    --快速查看表结构SELECT CASEWHENcol.colorder=1THENobj.name                 ELSE''            ENDAS表名,       col.colorderAS序号,       col.nameAS列名,       ISNULL(ep.[value],'')AS列说......
  • DSL查询语法
    DSL的查询语法很多,可在官方网站找到相关资料查询所有全文检索查询:利用分词器对用户输入内容分词,然后去倒序索引中匹配精确查询:根据精确词条查询数据,一般查找keyword,日期,数值等字段地理查询:根据经纬度查询符合查询:上面查询类型的组合查询模板GET /indexName/_search{ ......
  • SpringBoot教学资料5-SpringBoot一对多查询(带简单前端)
    项目展示:  项目结构:SQL:CREATETABLE`t_article`(`id`int(20)NOTNULLAUTO_INCREMENTCOMMENT'文章id',`title`varchar(200)DEFAULTNULLCOMMENT'文章标题',`content`longtextCOMMENT'文章内容',PRIMARYKEY(`id`))ENGINE=......
  • 公共语言运行库(CLR)开发系列课程(3):COM Interop基础 学习笔记
    公共语言运行库(CLR)开发系列课程(3):COMInterop基础学习笔记  上章地址什么是COMComponentObjectModel组建对象模型 基于接口(Interface)接口=协议IID标识接口V-table虚表方式调用单继承 对象(Object)实现一个或者多个接口举例:IDispatch......