views.py 793 B

1234567891011121314151617181920212223
  1. from django.contrib.auth.models import User, Group
  2. from rest_framework import viewsets
  3. from .serializers import UserSerializer, GroupSerializer
  4. from rest_framework.views import APIView
  5. from .permission import HasAPIKey
  6. from rest_framework.permissions import IsAuthenticated
  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 | IsAuthenticated]
  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 | IsAuthenticated]