Forráskód Böngészése

7-22作业第二步:DeptJobUserView初始化

DYaiu 4 éve
szülő
commit
b14d81b29f
3 módosított fájl, 15 hozzáadás és 2 törlés
  1. 8 1
      treeAndTable/serializer.py
  2. 2 1
      treeAndTable/urls.py
  3. 5 0
      treeAndTable/views.py

+ 8 - 1
treeAndTable/serializer.py

@@ -1,6 +1,6 @@
 from rest_framework import serializers
 
-from treeAndTable.models import Dept_job
+from treeAndTable.models import Dept_job, Dept_job_user
 
 
 class Dept_Job_Serializer(serializers.ModelSerializer):
@@ -8,3 +8,10 @@ class Dept_Job_Serializer(serializers.ModelSerializer):
         model = Dept_job
         # 全部都包含的意思
         fields = '__all__'
+
+
+class DeptJobUserSerializer(serializers.ModelSerializer):
+    class Meta:
+        model = Dept_job_user
+        # 全部都包含的意思
+        fields = '__all__'

+ 2 - 1
treeAndTable/urls.py

@@ -1,10 +1,11 @@
 from django.conf.urls import url
 from rest_framework_bulk.routes import BulkRouter
 
-from treeAndTable.views import DepartmentView, DeptAndJobView
+from treeAndTable.views import DepartmentView, DeptAndJobView,DeptJobUserView
 
 router = BulkRouter()
 router.register(r'job', DeptAndJobView)
+router.register(r'user', DeptJobUserView)
 
 urlpatterns = router.urls
 

+ 5 - 0
treeAndTable/views.py

@@ -117,3 +117,8 @@ class DeptAndJobView(ModelViewSet):
                 'name': DJ.job.name
             })
         return Response(data=data, status=status.HTTP_200_OK)
+
+
+class DeptJobUserView(ModelViewSet):
+    queryset = Dept_job.objects.all()
+    serializer_class = Dept_Job_Serializer