views.py 703 B

12345678910111213141516171819202122
  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. class UserViewSet(viewsets.ModelViewSet):
  6. """
  7. API endpoint that allows users to be viewed or edited.
  8. """
  9. queryset = User.objects.all().order_by('-date_joined')
  10. serializer_class = UserSerializer
  11. permission_classes = [permissions.IsAuthenticated]
  12. class GroupViewSet(viewsets.ModelViewSet):
  13. """
  14. API endpoint that allows groups to be viewed or edited.
  15. """
  16. queryset = Group.objects.all()
  17. serializer_class = GroupSerializer
  18. permission_classes = [permissions.IsAuthenticated]