views.py 765 B

123456789101112131415161718192021222324
  1. from django.contrib.auth.models import User, Group
  2. from rest_framework import viewsets
  3. from rest_framework import permissions
  4. from .serializers import UserSerializer, GroupSerializer
  5. from rest_framework.views import APIView
  6. from rest_framework_api_key.permissions import HasAPIKey
  7. class UserViewSet(viewsets.ModelViewSet):
  8. """
  9. API endpoint that allows users to be viewed or edited.
  10. """
  11. queryset = User.objects.all().order_by('-date_joined')
  12. serializer_class = UserSerializer
  13. permission_classes = [HasAPIKey]
  14. class GroupViewSet(viewsets.ModelViewSet):
  15. """
  16. API endpoint that allows groups to be viewed or edited.
  17. """
  18. queryset = Group.objects.all()
  19. serializer_class = GroupSerializer
  20. permission_classes = [HasAPIKey]