Ver código fonte

补充两张表的序列化类与路由

DYaiu 4 anos atrás
pai
commit
4679af728e
2 arquivos alterados com 19 adições e 3 exclusões
  1. 15 1
      basic/serializer.py
  2. 4 2
      basic/urls.py

+ 15 - 1
basic/serializer.py

@@ -1,7 +1,7 @@
 from rest_framework import serializers
 from rest_framework.serializers import ListSerializer
 
-from basic.models import Menu
+from basic.models import Menu, RouterMenu, GroupRouterMenu
 
 
 class MenuSerializer(serializers.ModelSerializer):
@@ -9,3 +9,17 @@ class MenuSerializer(serializers.ModelSerializer):
         model = Menu
         list_serializer = ListSerializer
         fields = '__all__'
+
+
+class RouterMenuSerializer(serializers.ModelSerializer):
+    class Meta:
+        model = RouterMenu
+        list_serializer = ListSerializer
+        fields = '__all__'
+
+
+class GroupRouterMenuSerializer(serializers.ModelSerializer):
+    class Meta:
+        model = GroupRouterMenu
+        list_serializer = ListSerializer
+        fields = '__all__'

+ 4 - 2
basic/urls.py

@@ -1,12 +1,14 @@
 from rest_framework_bulk.routes import BulkRouter
 from django.conf.urls import url
-from basic.views import MenuView, StatisticsView
+from basic.views import MenuView, StatisticsView, GroupRouterMenuView, RouterMenuView
 
 router = BulkRouter()
 router.register(r'menu', MenuView)
+router.register(r'router/menu', RouterMenuView)
 
 urlpatterns = router.urls
 
 urlpatterns += [
-    url('statistics', StatisticsView.as_view())
+    url('statistics', StatisticsView.as_view()),
+    url(r'user/menu', GroupRouterMenuView.as_view())
 ]