Przeglądaj źródła

Feature: Allow current user to fetch its information

pull/169/head
winkidney 5 lat temu
committed by Isaac Bythewood
rodzic
commit
c3b0cffea3
1 zmienionych plików z 12 dodań i 3 usunięć
  1. +12
    -3
      core/views.py

+ 12
- 3
core/views.py Wyświetl plik

@@ -9,9 +9,18 @@ from core.permissions import IsOwnerOrReadOnly
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
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):
@@ -43,7 +52,7 @@ class BoardViewSet(viewsets.ModelViewSet):


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'images', ImageViewSet)
drf_router.register(r'boards', BoardViewSet)

Ładowanie…
Anuluj
Zapisz