serializers
1 | # -*- coding: utf-8 -*- |
使用序列化1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33class QueryUser(APIView):
"""查找用户"""
def get(self, request):
"""
查询用户,仅能查到比自己权限低的
---
parameters:
- name: Authorization
description: token
required: true
type: string
paramType: header
- name: key
description: 手机号或者名字
required: false
type: string
paramType: query
"""
key = request.GET.get("key", "")
print(request.query_params)
users = models.Administrator.objects.filter(Q(mobile__contains=key) | Q(name__contains=key),
role__gt=request.user.role)
serializer_context = {'request': request}
data = AdministratorSerializer(users, context=serializer_context, many=True).data
return Response({"data": data}, status=status.HTTP_200_OK)
def post(self, request):
print(request.data)
return Response(status=status.HTTP_200_OK)