Skip to content

Commit

Permalink
Implement ImageDetailView
Browse files Browse the repository at this point in the history
  • Loading branch information
Themanwhosmellslikesugar committed Apr 22, 2021
1 parent cae52de commit b3ec076
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
3 changes: 2 additions & 1 deletion images/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,12 @@

from django.urls import re_path

from .views import ImageDeleteView, ImageNotesUpdateView, ListImagesView
from .views import ImageDeleteView, ImageDetailView, ImageNotesUpdateView, ListImagesView


urlpatterns = [ # pylint: disable=invalid-name
re_path('all/?$', ListImagesView.as_view(), name='images-all'),
re_path('delete/', ImageDeleteView.as_view(), name='image-delete'),
re_path('update_notes/$', ImageNotesUpdateView.as_view(), name='image-notes-update'),
re_path('image_detail/(?P<image_id>[0-9a-f-]+)/$', ImageDetailView.as_view(), name='image-detail'),
]
13 changes: 13 additions & 0 deletions images/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
from .models import Image
from .serializers import (
ImageDeleteSerializer,
ImageDetailSerializer,
ImageNotesUpdateSerializer,
ImageSerializer,
)
Expand Down Expand Up @@ -55,6 +56,18 @@ def delete(self, request, *args, **kwargs):
return JsonResponse(serializer.errors, status=status.HTTP_400_BAD_REQUEST)


class ImageDetailView(generics.RetrieveAPIView):
"""Returns the image which belong to the authenticated user. """

serializer_class = ImageDetailSerializer
permission_classes = (permissions.IsAuthenticated, )
lookup_field = 'image_id'

def get_queryset(self):
user = self.request.user
return Image.objects.filter(user=user)


class ImageNotesUpdateView(generics.UpdateAPIView):
"""Update image notes. """

Expand Down

0 comments on commit b3ec076

Please sign in to comment.