윤창목

children api added

......@@ -144,6 +144,30 @@ 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, *args, **kwargs):
if request.method == 'GET':
parent_item = Item.objects.get(pk = pk)
try:
parent_item = get_object_or_404(Item, pk = pk)
except parent_item.DoesNotExist:
return Response({'Error': 'Folder does not exist.'})
items = Item.objects.get(parent = parent_item.pk)
return Response(items)
if request.method == 'POST':
data = JSONParser().parse(request)
serializer = ItemSerializer(data=data)
if serializer.is_valid():
serializer.save()
return Response(serializer.data)
return Response(serializer.errors)
class SharedItemViewSet(viewsets.ModelViewSet):
......@@ -181,4 +205,4 @@ class SharedItemViewSet(viewsets.ModelViewSet):
item = ItemViewSet.as_view({
'delete': 'destroy',
})
\ No newline at end of file
})
......
......@@ -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'^children/$', views.ItemViewSet.children, name='children'),
]
......