권주희

setting the default function

......@@ -18,7 +18,3 @@ class ItemSerializer(serializers.ModelSerializer):
model = Item
fields = '__all__'
class SharedItemSerializer(serializers.ModelSerializer):
class Meta:
model = Item
fields = '__all__'
......
......@@ -13,7 +13,7 @@ from rest_framework.decorators import action
from rest_framework.permissions import IsAuthenticated, AllowAny
from api.models import Item, SharedItem
from api.serializers import UserSerializer,GroupSerializer,ItemSerializer,SharedItemSerializer
from api.serializers import UserSerializer,GroupSerializer,ItemSerializer
from rest_framework import status
from annoying.functions import get_object_or_None
......@@ -26,13 +26,16 @@ class UserViewSet(viewsets.ModelViewSet):
permission_classes = [permissions.IsAuthenticated]
class ItemViewSet(viewsets.ModelViewSet):
class ItemViewSet(viewsets.ViewSet):
queryset = Item.objects.all()
serializer_class = ItemSerializer
permission_classes = [permissions.IsAuthenticatedOrReadOnly, permissions.AllowAny,
#IsOwnerOrReadOnly
]
permission_classes_by_action = {'get': [permissions.AllowAny],
'destroy': [permissions.AllowAny]}
# url: items/search
@action(methods=['GET'], detail=False, permission_classes=[AllowAny], url_path='search', url_name='search')
def search(self, request):
......@@ -44,12 +47,38 @@ class ItemViewSet(viewsets.ModelViewSet):
json_data = json.loads(data)
return Response({'data': {'list' : json_data}}, status=status.HTTP_200_OK)
# url: items/11/
# 마지막 slash도 써주어야함
def get(self, request, pk):
print(pk)
return Response({'message': "info complete"}, status=status.HTTP_200_OK)
# url: items/11/
# 마지막 slash도 써주어야함
def destroy(self, request, pk):
if request.method == 'DELETE':
print(pk)
# keyword = request.GET.get('keyword', '')
# item_list = Item.objects.filter(name__icontains=keyword)
#
# data = serializers.serialize("json", item_list)
# json_data = json.loads(data)
# return Response({'message': "delete complete"}, status=status.HTTP_200_OK)
return Response(status=status.HTTP_204_NO_CONTENT)
def get_permissions(self):
try:
# return permission_classes depending on `action`
return [permission() for permission in self.permission_classes_by_action[self.action]]
except KeyError:
# action is not set return default permission_classes
return [permission() for permission in self.permission_classes]
class SharedItemViewSet(viewsets.ModelViewSet):
queryset = SharedItem.objects.all()
serializer_class = SharedItemSerializer
# serializer_class = SharedItemSerializer
permission_classes = [permissions.IsAuthenticatedOrReadOnly, permissions.AllowAny,
# IsOwnerOrReadOnly
]
......@@ -75,4 +104,8 @@ class SharedItemViewSet(viewsets.ModelViewSet):
item_json = serializers.serialize("json", item)
json_data = json.loads(item_json)
return Response({"shared": sharedfile.created_time , 'data': json_data}, status=status.HTTP_200_OK)
\ No newline at end of file
return Response({"shared": sharedfile.created_time , 'data': json_data}, status=status.HTTP_200_OK)
item = ItemViewSet.as_view({
'delete': 'destroy',
})
\ No newline at end of file
......