권주희

implement children get api

......@@ -148,6 +148,36 @@ class ItemViewSet(viewsets.ViewSet):
# action is not set return default permission_classes
return [permission() for permission in self.permission_classes]
# url: items/{key}/children/
@action(methods=['GET', 'POST'], detail=True, permission_classes=[AllowAny],
url_path='children', url_name='children')
def children(self, request, pk):
if request.method == 'GET':
children = Item.objects.filter(parent = pk)
children_data = serializers.serialize("json", children)
json_children = json.loads(children_data)
parent = Item.objects.filter(item_id=pk) #item
parent_data = serializers.serialize("json", parent)
json_parent = json.loads(parent_data)[0]['fields']
res = json_parent
res['id'] = pk
children_list = []
for i in json_children:
t = i['fields']
t['id'] = i['pk']
children_list.append(t)
res['list'] = children_list
return Response({'data': res}, status=status.HTTP_200_OK)
if request.method == 'POST':
print("post")
#
# data = JSONParser().parse(request)
# serializer = ItemSerializer(data=data)
# if serializer.is_valid():
# serializer.save()
# return Response(serializer.data)
return Response({'message': 'post is not existed.'}, status=status.HTTP_204_NO_CONTENT)
class SharedItemViewSet(viewsets.ModelViewSet):
......
......@@ -33,5 +33,6 @@ urlpatterns = [
url(r'^<int:pk>/share/$', views.SharedItemViewSet.share, name='share'),
url(r'^<int:pk>/move/$', views.ItemViewSet.move, name='move'),
url(r'^<int:pk>/copy/$', views.ItemViewSet.copy, name='copy'),
url(r'^<int:pk>/children/$', views.ItemViewSet.children, name='copy'),
]
......