2020-03-18 13:36:40 +00:00
|
|
|
from rest_framework import viewsets, permissions, status
|
|
|
|
from .serializers import *
|
|
|
|
|
|
|
|
class UserViewSet(viewsets.ReadOnlyModelViewSet):
|
|
|
|
serializer_class = UserSerializer
|
|
|
|
permission_classes = [permissions.IsAuthenticated]
|
|
|
|
|
|
|
|
def get_queryset(self):
|
|
|
|
if self.request.user.is_superuser:
|
|
|
|
obj = get_user_model().objects.all()
|
|
|
|
else:
|
|
|
|
# This is a bit stupid: we have a user, we create a queryset by
|
2020-03-18 13:53:26 +00:00
|
|
|
# matching on the username. But I don't know a "nicer" way.
|
|
|
|
# Nico, 2020-03-18
|
2020-03-18 13:36:40 +00:00
|
|
|
obj = get_user_model().objects.filter(username=self.request.user.username)
|
|
|
|
|
|
|
|
return obj
|