Explorar el Código

payment的后端使用ModelViewSet加反序列化

DYaiu hace 4 años
padre
commit
ab33fd79ef
Se han modificado 4 ficheros con 33 adiciones y 3 borrados
  1. 2 1
      my_project/urls.py
  2. 11 0
      payment/serializer.py
  3. 11 0
      payment/urls.py
  4. 9 2
      payment/views.py

+ 2 - 1
my_project/urls.py

@@ -21,5 +21,6 @@ urlpatterns = [
     path('admin/', admin.site.urls),
     url(r'^', include('workreport.urls')),
     url(r'^', include('workTtree.urls')),
-    url(r'^treeAndTable/', include('treeAndTable.urls'))
+    url(r'^treeAndTable/', include('treeAndTable.urls')),
+    url(r'^payment/',include('payment.urls'))
 ]

+ 11 - 0
payment/serializer.py

@@ -0,0 +1,11 @@
+from rest_framework import serializers
+from rest_framework.serializers import ListSerializer
+
+from payment.models import Payment
+
+
+class PaymentSerializer(serializers.ModelSerializer):
+    class Meta:
+        model = Payment
+        list_serializer = ListSerializer
+        fields = '__all__'

+ 11 - 0
payment/urls.py

@@ -0,0 +1,11 @@
+from rest_framework_bulk.routes import BulkRouter
+
+from payment.views import PaymentView
+
+router = BulkRouter()
+router.register(r'payment', PaymentView)
+
+urlpatterns = router.urls
+
+urlpatterns += [
+]

+ 9 - 2
payment/views.py

@@ -1,3 +1,10 @@
-from django.shortcuts import render
+from rest_framework.viewsets import ModelViewSet
 
-# Create your views here.
+from payment.models import Payment
+from payment.serializer import PaymentSerializer
+
+
+class PaymentView(ModelViewSet):
+    queryset = Payment.objects.all()
+    serializer_class = PaymentSerializer
+    pagination_class = None