views.py 609 B

1234567891011121314151617181920
  1. from rest_framework import viewsets
  2. from glitchtip.permissions import UserOnlyPermission
  3. from .models import APIToken
  4. from .serializers import APITokenSerializer
  5. class APITokenViewSet(viewsets.ModelViewSet):
  6. queryset = APIToken.objects.all()
  7. serializer_class = APITokenSerializer
  8. permission_classes = [UserOnlyPermission]
  9. def get_queryset(self):
  10. if not self.request.user.is_authenticated:
  11. return self.queryset.none()
  12. return self.queryset.filter(user=self.request.user)
  13. def perform_create(self, serializer):
  14. serializer.save(user=self.request.user)