from django.shortcuts import render
from rest_framework.views import APIView
from rest_framework.viewsets import ModelViewSet
from .models import Consult
# Create your views here.
from rest_framework import serializers
from utils.custom import CommonPagination
from .models import Consult
from django_filters.rest_framework import DjangoFilterBackend
from rest_framework.filters import OrderingFilter, SearchFilter
from rest_framework.decorators import action
from cms.models import Material
from rest_framework.response import Response
class ConsultSerializer(serializers.ModelSerializer):
    """
    咨询序列化
    """
    class Meta:
        model = Consult
        fields = '__all__'

class ConsultViewSet(ModelViewSet):
    """
    咨询 增删改查
    """
    perms_map = [
        {'get': '*'}, {'post': '*'},
        {'put': 'consult_update'}, {'delete': 'consult_delete'}]
    queryset = Consult.objects.filter(is_delete=0)
    serializer_class = ConsultSerializer
    pagination_class = CommonPagination
    filter_backends = [DjangoFilterBackend,SearchFilter, OrderingFilter]
    search_fields = ['name','tests', 'phone']
    ordering=['-pk']

