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.

views.py 1016 B

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