|
|
import logging
|
|
|
|
|
|
from django.db.models import Q
|
|
|
from django.utils.decorators import method_decorator
|
|
|
from drf_yasg import openapi
|
|
|
from drf_yasg.utils import swagger_auto_schema
|
|
|
from rest_framework import viewsets
|
|
|
from goods_info.models import UnitsModel
|
|
|
|
|
|
from goods_info.serializer.units_serializer import UnitsSerializer
|
|
|
from ERP_5.utils.paginations import GlobalPagination
|
|
|
from ERP_5.utils.base_views import MultipleDestroyMixin, MultipleOpenMixin
|
|
|
|
|
|
logger = logging.getLogger('my')
|
|
|
|
|
|
param3 = openapi.Parameter(name='name', type=openapi.TYPE_STRING, description="名称关键字", in_=openapi.IN_QUERY)
|
|
|
|
|
|
|
|
|
@method_decorator(name='list', decorator=swagger_auto_schema(
|
|
|
manual_parameters=[param3],
|
|
|
operation_description="计量单位的搜索过滤")
|
|
|
)
|
|
|
class UnitsView(viewsets.ModelViewSet, MultipleDestroyMixin, MultipleOpenMixin):
|
|
|
"""
|
|
|
create:
|
|
|
计量单位--新增
|
|
|
|
|
|
计量单位新增, status: 201(成功), return: 新增计量单位信息
|
|
|
|
|
|
destroy:
|
|
|
计量单位--删除
|
|
|
|
|
|
计量单位删除, status: 204(成功), return: None
|
|
|
|
|
|
multiple_delete:
|
|
|
计量单位--批量删除,必传参数:ids=[1,2,3,4...]
|
|
|
|
|
|
计量单位批量删除, status: 204(成功), return: None
|
|
|
|
|
|
multiple_open:
|
|
|
计量单位--批量启用或者禁用,必传(json)参数:ids=[1,2,3,4...](列表中可以只有一个),is_open=1/0
|
|
|
|
|
|
{
|
|
|
"ids":[1,2],
|
|
|
"is_open":"0"
|
|
|
}
|
|
|
is_open=1表示禁用,is_open=0表示启用,
|
|
|
计量单位批量启用或者禁用, status: 204(成功), return: None
|
|
|
|
|
|
update:
|
|
|
计量单位--修改,
|
|
|
|
|
|
计量单位修改, status: 200(成功), return: 修改后的计量单位信息
|
|
|
|
|
|
partial_update:
|
|
|
计量单位--局部修改,可以传参任意属性的值,服务器会修改指定的属性值
|
|
|
|
|
|
计量单位局部修改, status: 200(成功), return: 修改后的计量单位信息
|
|
|
|
|
|
list:
|
|
|
计量单位--获取分页列表,可选json参数:name(名称)
|
|
|
|
|
|
{
|
|
|
"name":"长沙",
|
|
|
}
|
|
|
计量单位列表信息, status: 200(成功), return: 计量单位信息列表
|
|
|
|
|
|
retrieve:
|
|
|
查询某一个计量单位
|
|
|
|
|
|
查询指定ID的计量单位, status: 200(成功), return: 用户计量单位
|
|
|
"""
|
|
|
|
|
|
queryset = UnitsModel.objects.all()
|
|
|
serializer_class = UnitsSerializer
|
|
|
pagination_class = GlobalPagination
|
|
|
|
|
|
def get_queryset(self):
|
|
|
if self.action == 'list': # 过滤查询
|
|
|
# 获取请求参数(在json中):name,phone, mobile
|
|
|
name = self.request.data.get('name', None)
|
|
|
query = Q()
|
|
|
if name:
|
|
|
# 关键字查询两个字段
|
|
|
query.add(Q(basic_name__contains=name), 'OR') # 多条件组合
|
|
|
query.add(Q(backup_name__contains=name), 'OR')
|
|
|
return UnitsModel.objects.filter(query).all()
|
|
|
else:
|
|
|
return UnitsModel.objects.all()
|