Browse Source

Feature: Allow current user to fetch its information

pull/169/head
winkidney 5 years ago
committed by Isaac Bythewood
parent
commit
c3b0cffea3
1 changed files with 12 additions and 3 deletions
  1. +12
    -3
      core/views.py

+ 12
- 3
core/views.py View File

@@ -9,9 +9,18 @@ from core.permissions import IsOwnerOrReadOnly
from users.models import User from users.models import User




class UserViewSet(mixins.RetrieveModelMixin, GenericViewSet):
queryset = User.objects.all()
class UserViewSet(
mixins.RetrieveModelMixin,
mixins.ListModelMixin,
GenericViewSet,
):
serializer_class = api.UserSerializer serializer_class = api.UserSerializer
pagination_class = None

def get_queryset(self):
if self.request.user.is_anonymous:
return User.objects.none()
return User.objects.filter(id=self.request.user.id)




class ImageViewSet(mixins.CreateModelMixin, GenericViewSet): class ImageViewSet(mixins.CreateModelMixin, GenericViewSet):
@@ -43,7 +52,7 @@ class BoardViewSet(viewsets.ModelViewSet):




drf_router = routers.DefaultRouter() drf_router = routers.DefaultRouter()
drf_router.register(r'users', UserViewSet)
drf_router.register(r'users', UserViewSet, base_name="user")
drf_router.register(r'pins', PinViewSet) drf_router.register(r'pins', PinViewSet)
drf_router.register(r'images', ImageViewSet) drf_router.register(r'images', ImageViewSet)
drf_router.register(r'boards', BoardViewSet) drf_router.register(r'boards', BoardViewSet)

Loading…
Cancel
Save