真实的国产乱ⅩXXX66竹夫人,五月香六月婷婷激情综合,亚洲日本VA一区二区三区,亚洲精品一区二区三区麻豆

成都創(chuàng)新互聯(lián)網(wǎng)站制作重慶分公司

免費(fèi)課頁(yè)面前端搭建和后端課程分類接口、課程群查接口設(shè)計(jì)

免費(fèi)課頁(yè)面前端搭建

點(diǎn)擊查看代碼





課程分類接口實(shí)現(xiàn)

serializes.py

創(chuàng)新互聯(lián)主要從事網(wǎng)站建設(shè)、網(wǎng)站制作、網(wǎng)頁(yè)設(shè)計(jì)、企業(yè)做網(wǎng)站、公司建網(wǎng)站等業(yè)務(wù)。立足成都服務(wù)杞縣,十年網(wǎng)站建設(shè)經(jīng)驗(yàn),價(jià)格優(yōu)惠、服務(wù)專業(yè),歡迎來(lái)電咨詢建站服務(wù):13518219792

from rest_framework import serializers
from . import models

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

views.py

from django.shortcuts import render
from rest_framework.viewsets import GenericViewSet
from rest_framework.mixins import ListModelMixin
from . import models
from . import serializes


# Create your views here.
class CourseCategory(GenericViewSet,ListModelMixin):
    queryset = models.CourseCategory.objects.filter(is_delete=False,is_show=True).order_by('orders')
    serializer_class = serializes.CourseCategorySerialize

urls.py

from django.urls import path,re_path,include
from course import views
from rest_framework.routers import SimpleRouter

router = SimpleRouter()
router.register('categories',views.CourseCategory,'category')

urlpatterns = [
    path('',include(router.urls)),
]

課程群查接口搭建

serializes.py

from rest_framework import serializers
from . import models

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


class TeacherSerialize(serializers.ModelSerializer):
    class Meta:
        model = models.Teacher
        fields = ('name', 'role_name', 'title', 'signature', 'image', 'brief')


class CourseModelSerialize(serializers.ModelSerializer):
    # 由于課程也需要teacher表相關(guān)的信息,所以可以采用子序列化的方式,獲取teacher相關(guān)的信息
    teacher = TeacherSerialize()
    class Meta:
        model = models.Course
        fields = ['id',
                  'name',
                  'price',
                  'course_img',
                  'brief',
                  'attachment_path',
                  'pub_sections',
                  'students',
                  'period',
                  'sections',
                  'teacher',
                  'course_type_name', # 以下字段是models里的方法名
                  'level_name',
                  'status_name',
                  'section_list'
                  ]

views.py

from rest_framework.filters import OrderingFilter,SearchFilter
from django_filters.rest_framework import DjangoFilterBackend

class CourseView(GenericViewSet,ListModelMixin):
    queryset = models.Course.objects.filter(is_delete=False,is_show=True).order_by('orders')
    serializer_class = serializes.CourseModelSerialize
    filter_backends = [OrderingFilter,DjangoFilterBackend]
    ordering_fields = ['id','price','students']
    filterset_fields = ['course_category',]

當(dāng)前標(biāo)題:免費(fèi)課頁(yè)面前端搭建和后端課程分類接口、課程群查接口設(shè)計(jì)
路徑分享:http://weahome.cn/article/dsogdio.html

其他資訊

在線咨詢

微信咨詢

電話咨詢

028-86922220(工作日)

18980820575(7×24)

提交需求

返回頂部