1
0
Fork 0

Add ancestors, descendants and siblings API detail routes

This commit is contained in:
Piotr Dobrowolski 2017-04-24 21:57:22 +02:00
parent 95b6ac712b
commit 7751f7f682
1 changed files with 15 additions and 4 deletions

View File

@ -27,9 +27,20 @@ class ItemViewSet(viewsets.ModelViewSet):
@detail_route() @detail_route()
def children(self, request, pk): def children(self, request, pk):
"""
Returns a list of all the group names that the given
user belongs to.
"""
item = self.get_object() item = self.get_object()
return Response(self.serializer_class(item.get_children().all(), many=True).data) return Response(self.serializer_class(item.get_children().all(), many=True).data)
@detail_route()
def ancestors(self, request, pk):
item = self.get_object()
return Response(self.serializer_class(item.get_ancestors().all(), many=True).data)
@detail_route()
def descendants(self, request, pk):
item = self.get_object()
return Response(self.serializer_class(item.get_descendants().all(), many=True).data)
@detail_route()
def siblings(self, request, pk):
item = self.get_object()
return Response(self.serializer_class(item.get_siblings().all(), many=True).data)