選択できるのは25トピックまでです。 トピックは、先頭が英数字で、英数字とダッシュ('-')を使用した35文字以内のものにしてください。
 
 
 
 
 
 

43 行
1.5 KiB

  1. from django_filters.rest_framework import DjangoFilterBackend
  2. from rest_framework import viewsets, mixins, routers
  3. from rest_framework.filters import SearchFilter, OrderingFilter
  4. from rest_framework.viewsets import GenericViewSet
  5. from core import serializers as api
  6. from core.models import Image, Pin, Board
  7. from core.permissions import IsOwnerOrReadOnly
  8. class ImageViewSet(mixins.CreateModelMixin, GenericViewSet):
  9. queryset = Image.objects.all()
  10. serializer_class = api.ImageSerializer
  11. def create(self, request, *args, **kwargs):
  12. return super(ImageViewSet, self).create(request, *args, **kwargs)
  13. class PinViewSet(viewsets.ModelViewSet):
  14. queryset = Pin.objects.all().select_related('image', 'submitter')
  15. serializer_class = api.PinSerializer
  16. filter_backends = (DjangoFilterBackend, SearchFilter, OrderingFilter)
  17. filter_fields = ("submitter__username", 'tags__name', )
  18. ordering_fields = ('-id', )
  19. ordering = ('-id', )
  20. permission_classes = [IsOwnerOrReadOnly("submitter"), ]
  21. class BoardViewSet(viewsets.ModelViewSet):
  22. queryset = Board.objects.all()
  23. serializer_class = api.BoardSerializer
  24. filter_backends = (DjangoFilterBackend, OrderingFilter)
  25. filter_fields = ("submitter__username", )
  26. ordering_fields = ('-id', )
  27. ordering = ('-id', )
  28. permission_classes = [IsOwnerOrReadOnly("submitter"), ]
  29. drf_router = routers.DefaultRouter()
  30. drf_router.register(r'pins', PinViewSet)
  31. drf_router.register(r'images', ImageViewSet)
  32. drf_router.register(r'boards', BoardViewSet)