hberp/hb_server/apps/sam/views.py

24 lines
802 B
Python

from apps.sam.serializers import CustomerCreateUpdateSerializer, CustomerSerializer
from apps.sam.models import Customer
from rest_framework.viewsets import ModelViewSet
from apps.system.mixins import CreateUpdateCustomMixin
from django.shortcuts import render
# Create your views here.
class CustomerViewSet(CreateUpdateCustomMixin, ModelViewSet):
"""
客户-增删改查
"""
perms_map = {'*': '*'}
queryset = Customer.objects.all()
serializer_class = CustomerSerializer
search_fields = ['name', 'contact']
filterset_fields = []
ordering_fields = ['create_time']
ordering = ['-create_time']
def get_serializer_class(self):
if self.action in ['create', 'update']:
return CustomerCreateUpdateSerializer
return CustomerSerializer