Selaa lähdekoodia

Feature: Allow current user to fetch its information

pull/169/head
winkidney 5 vuotta sitten
committed by Isaac Bythewood
vanhempi
commit
c3b0cffea3
1 muutettua tiedostoa jossa 12 lisäystä ja 3 poistoa
  1. +12
    -3
      core/views.py

+ 12
- 3
core/views.py Näytä tiedosto

@@ -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)

Ladataan…
Peruuta
Tallenna