Showing
2 changed files
with
31 additions
and
0 deletions
... | @@ -148,6 +148,36 @@ class ItemViewSet(viewsets.ViewSet): | ... | @@ -148,6 +148,36 @@ class ItemViewSet(viewsets.ViewSet): |
148 | # action is not set return default permission_classes | 148 | # action is not set return default permission_classes |
149 | return [permission() for permission in self.permission_classes] | 149 | return [permission() for permission in self.permission_classes] |
150 | 150 | ||
151 | + # url: items/{key}/children/ | ||
152 | + @action(methods=['GET', 'POST'], detail=True, permission_classes=[AllowAny], | ||
153 | + url_path='children', url_name='children') | ||
154 | + def children(self, request, pk): | ||
155 | + if request.method == 'GET': | ||
156 | + children = Item.objects.filter(parent = pk) | ||
157 | + children_data = serializers.serialize("json", children) | ||
158 | + json_children = json.loads(children_data) | ||
159 | + parent = Item.objects.filter(item_id=pk) #item | ||
160 | + parent_data = serializers.serialize("json", parent) | ||
161 | + json_parent = json.loads(parent_data)[0]['fields'] | ||
162 | + res = json_parent | ||
163 | + res['id'] = pk | ||
164 | + children_list = [] | ||
165 | + for i in json_children: | ||
166 | + t = i['fields'] | ||
167 | + t['id'] = i['pk'] | ||
168 | + children_list.append(t) | ||
169 | + res['list'] = children_list | ||
170 | + return Response({'data': res}, status=status.HTTP_200_OK) | ||
171 | + if request.method == 'POST': | ||
172 | + print("post") | ||
173 | + # | ||
174 | + # data = JSONParser().parse(request) | ||
175 | + # serializer = ItemSerializer(data=data) | ||
176 | + # if serializer.is_valid(): | ||
177 | + # serializer.save() | ||
178 | + # return Response(serializer.data) | ||
179 | + return Response({'message': 'post is not existed.'}, status=status.HTTP_204_NO_CONTENT) | ||
180 | + | ||
151 | 181 | ||
152 | class SharedItemViewSet(viewsets.ModelViewSet): | 182 | class SharedItemViewSet(viewsets.ModelViewSet): |
153 | 183 | ... | ... |
... | @@ -33,5 +33,6 @@ urlpatterns = [ | ... | @@ -33,5 +33,6 @@ urlpatterns = [ |
33 | url(r'^<int:pk>/share/$', views.SharedItemViewSet.share, name='share'), | 33 | url(r'^<int:pk>/share/$', views.SharedItemViewSet.share, name='share'), |
34 | url(r'^<int:pk>/move/$', views.ItemViewSet.move, name='move'), | 34 | url(r'^<int:pk>/move/$', views.ItemViewSet.move, name='move'), |
35 | url(r'^<int:pk>/copy/$', views.ItemViewSet.copy, name='copy'), | 35 | url(r'^<int:pk>/copy/$', views.ItemViewSet.copy, name='copy'), |
36 | + url(r'^<int:pk>/children/$', views.ItemViewSet.children, name='copy'), | ||
36 | 37 | ||
37 | ] | 38 | ] | ... | ... |
-
Please register or login to post a comment