1. 程式人生 > 實用技巧 >課程單查介面與章節介面

課程單查介面與章節介面

課程單查介面與章節介面

課程單查介面

class CourseView(GenericViewSet, RetrieveModelMixin):
    queryset = models.Course.objects.filter(is_delete=False, is_show=True).order_by('orders')
    serializer_class = serializer.CourseModelSerializer

章節介面

class CourseChapterView(GenericViewSet,ListModelMixin):
    queryset = models.CourseChapter.objects.filter(is_delete=False,is_show=True)
    serializer_class = serializer.CourseChapterSerializer

    # 可以根據課程ID來查
    filter_backends = [DjangoFilterBackend]
    filter_fields = ['course']  # 根據課程來過濾課時
    

# CourseChapterSerializer

class CourseSectionSerializer(serializers.ModelSerializer):
    class Meta:
        model=models.CourseSection
        fields = ['name','orders','duration','free_trail','section_link','section_type_name']

class CourseChapterSerializer(serializers.ModelSerializer):
    # 子序列化列
    coursesections =CourseSectionSerializer(many=True)
    class Meta:
        model = models.CourseChapter
        fields = ['name','summary','chapter','coursesections']