03.通过课程查询商品信息
# 1.只需要修改/course/course/1/
返回的数据即可
# 1.1 course/serializers.py
添加商品信息序列化
# 添加显示商品字段
from goods.serializers import GoodsSerializer
class CourseDeepSerializer(CourseSerializer):
goods_set = GoodsSerializer(many=True)
chapters = ChaptersSerializer(many=True)
1
2
3
4
5
2
3
4
5
# 1.2 在 goods/serializers.py
中添加序列化函数
# -*- coding: utf-8 -*-
from rest_framework import serializers
from goods.models import Goods
class GoodsSerializer(serializers.ModelSerializer):
class Meta:
model = Goods
fields = '__all__' # 所有字段
1
2
3
4
5
6
7
8
2
3
4
5
6
7
8
# 2.测试
Http://192.168.56.100:8888/course/course/1/
1
{
"id": 1,
"goods_set": [
{
"id": 2,
"create_time": "2020-10-13T03:42:53.449302Z",
"update_time": "2020-10-13T03:42:53.449842Z",
"goods_type": "1",
"product_id": "1",
"title": "Linux课程体系",
"price": "55.00",
"channel_type": "1",
"period": 365,
"is_launched": true,
"course": 1
}
],
"chapters": [
{
"id": 1,
"sections": [
{
"id": 1,
"create_time": "2020-10-11T14:57:14.151331Z",
"update_time": "2020-10-11T14:57:14.151364Z",
"title": "Linux 系统简介",
"serial_num": 1,
"learn_time": 1,
"video": "http://192.168.56.100:8888/media/videos/20201011/07.%E6%A3%80%E6%9F%A5%E7%94%A8%E6%88%B7%E5%90%8D%E6%98%AF%E5%90%A6%E4%BD%BF%E7%94%A8%E6%8E%A5%E5%8F%A3.mp4",
"seq_num": 1,
"chapters": 1
}
],
"create_time": "2020-10-11T14:56:34.585658Z",
"update_time": "2020-10-11T14:56:34.585689Z",
"title": "Linux 系统简介",
"serial_num": 1,
"course": 1
}
],
"create_time": "2020-10-11T14:44:31.252836Z",
"update_time": "2020-10-12T12:32:20.045791Z",
"title": "Linux入门课程",
"desc": "要在实验楼愉快地学习,先要熟练地使用 Linux,本实验介绍 Linux 基本操作,shell 环境下的常用命令。",
"img": "http://192.168.56.100:8888/media/course/linux.jpg",
"status": "1",
"attention": 111,
"learner": 222,
"course_type": 3,
"course_tag": [
3
]
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
上次更新: 2024/3/13 15:35:10