1 2 3 4

通过课程查询商品信息

1.只需要修改/course/sourse/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 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__' # 所有字段

 

2.测试

Http://192.168.56.100:8888/course/course/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
    ] 
}

 

 

 

 

 

 

posted @ 2020-10-15 16:18  发哥奇妙IT之旅  阅读(79)  评论(0编辑  收藏  举报