You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

38 line
1.2 KiB

  1. from rest_framework import viewsets, mixins, routers
  2. from rest_framework.filters import SearchFilter, OrderingFilter
  3. from rest_framework.viewsets import GenericViewSet
  4. from core import drf_api as api
  5. from core.models import Image, Pin
  6. from core.permissions import IsOwnerOrReadOnly
  7. from users.models import User
  8. class UserViewSet(viewsets.ModelViewSet):
  9. queryset = User.objects.all()
  10. serializer_class = api.UserSerializer
  11. class ImageViewSet(mixins.CreateModelMixin, GenericViewSet):
  12. queryset = Image.objects.all()
  13. serializer_class = api.ImageSerializer
  14. def create(self, request, *args, **kwargs):
  15. return super(ImageViewSet, self).create(request, *args, **kwargs)
  16. class PinViewSet(viewsets.ModelViewSet):
  17. queryset = Pin.objects.all()
  18. serializer_class = api.PinSerializer
  19. filter_backends = (SearchFilter, OrderingFilter)
  20. search_fields = ('=submitter__username', )
  21. ordering_fields = ('id', )
  22. ordering = ('id', )
  23. permission_classes = [IsOwnerOrReadOnly("submitter"), ]
  24. drf_router = routers.DefaultRouter()
  25. drf_router.register(r'users', UserViewSet)
  26. drf_router.register(r'pins', PinViewSet)
  27. drf_router.register(r'images', ImageViewSet)