|
@@ -1,4 +1,5 @@
|
|
from django.db.models import F
|
|
from django.db.models import F
|
|
|
|
+from django.forms import model_to_dict
|
|
from rest_framework import status
|
|
from rest_framework import status
|
|
from rest_framework.response import Response
|
|
from rest_framework.response import Response
|
|
from rest_framework.views import APIView
|
|
from rest_framework.views import APIView
|
|
@@ -51,6 +52,7 @@ class DepartmentView(APIView):
|
|
return Response(data={}, status=status.HTTP_400_BAD_REQUEST)
|
|
return Response(data={}, status=status.HTTP_400_BAD_REQUEST)
|
|
return Response(data=data, status=status.HTTP_200_OK)
|
|
return Response(data=data, status=status.HTTP_200_OK)
|
|
|
|
|
|
|
|
+
|
|
'''
|
|
'''
|
|
post
|
|
post
|
|
{
|
|
{
|
|
@@ -67,6 +69,8 @@ Put
|
|
"job":6
|
|
"job":6
|
|
}
|
|
}
|
|
'''
|
|
'''
|
|
|
|
+
|
|
|
|
+
|
|
class DeptAndJobView(ModelViewSet):
|
|
class DeptAndJobView(ModelViewSet):
|
|
queryset = Dept_job.objects.all()
|
|
queryset = Dept_job.objects.all()
|
|
serializer_class = Dept_Job_Serializer
|
|
serializer_class = Dept_Job_Serializer
|
|
@@ -86,7 +90,7 @@ class DeptAndJobView(ModelViewSet):
|
|
deptId = request.data['dept_id']
|
|
deptId = request.data['dept_id']
|
|
name = request.data['name']
|
|
name = request.data['name']
|
|
except Exception:
|
|
except Exception:
|
|
- return Response(data={'msg':'请求参数错误'}, status=status.HTTP_400_BAD_REQUEST)
|
|
|
|
|
|
+ return Response(data={'msg': '请求参数错误'}, status=status.HTTP_400_BAD_REQUEST)
|
|
try:
|
|
try:
|
|
# 如果给定的岗位名称不存在岗位表直接新建一个岗位
|
|
# 如果给定的岗位名称不存在岗位表直接新建一个岗位
|
|
job = Job.objects.get(name=name)
|
|
job = Job.objects.get(name=name)
|
|
@@ -96,3 +100,16 @@ class DeptAndJobView(ModelViewSet):
|
|
Dept_job.objects.create(dept_id=deptId, job_id=job.id)
|
|
Dept_job.objects.create(dept_id=deptId, job_id=job.id)
|
|
|
|
|
|
return Response(data={'msg': 'success'}, status=status.HTTP_200_OK)
|
|
return Response(data={'msg': 'success'}, status=status.HTTP_200_OK)
|
|
|
|
+
|
|
|
|
+ '''
|
|
|
|
+ 根据部门id获取部门岗位中间表的该部门所有岗位信息
|
|
|
|
+ '''
|
|
|
|
+
|
|
|
|
+ def list(self, request, *args, **kwargs):
|
|
|
|
+ deptId = request.GET.get('dept_id')
|
|
|
|
+ print(deptId)
|
|
|
|
+ deptAndJob = Dept_job.objects.filter(dept_id=deptId).all()
|
|
|
|
+ data = []
|
|
|
|
+ for DJ in deptAndJob:
|
|
|
|
+ data.append(model_to_dict(DJ.job))
|
|
|
|
+ return Response(data=data, status=status.HTTP_200_OK)
|