43 搜索功能/2-搜索后台接口

路由:course/urls.py
router.register('coursesearch', views.SearchCourseViewSet, 'coursesearch') # 搜索课程
视图:course/views.py
from rest_framework.viewsets import GenericViewSet
from rest_framework.mixins import ListModelMixin
from rest_framework.filters import SearchFilter
from . import models, serializers

# 搜索课程接口
class SearchCourseViewSet(GenericViewSet, ListModelMixin):
    queryset = models.Course.objects.filter(is_delete=False, is_show=True).all()
    serializer_class = serializers.CourseSerializer

    pagination_class = pagination.PageNumberPagination

    filter_backends = [SearchFilter]
    search_fields = ['name']

 

上一篇:网页美化--飘桃花效果


下一篇:1. ibatis 查询的sql列存在相同的列名