文章目录
from django.shortcuts import render
# Create your views here.
from rest_framework.viewsets import ModelViewSet
from course.serializers import CourseSer,ChaptersSer,SectionsSer,CtagSer,CtypeSer,CourseSer2
from course.models import *
# 类别
class CtypeV(ModelViewSet):
queryset=CourseType.objects.all()
serializer_class=CtypeSer
# 标签
class CtagV(ModelViewSet):
queryset=CourseTag.objects.all()
serializer_class=CtagSer
# 课程
#课程(postman测试)添加标签多对多字段以list形式
class CourseV(ModelViewSet):
queryset=Course.objects.all()
serializer_class=CourseSer
def get_serializer_class(self):
#.action modelviewset中识别数据类型的方法(list,str)
判断是list就走展示多对多外键序列化器
if self.action=='list':
return CourseSer2
else:
return CourseSer
# 章
class ChapterV(ModelViewSet):
queryset=Chapters.objects.all()
serializer_class=Cha