2023-03-01 22:58:22 +08:00
|
|
|
from rest_framework.permissions import IsAuthenticated
|
2023-02-24 00:13:44 +08:00
|
|
|
from rest_framework import viewsets
|
|
|
|
from .serializers import NoteSerializer
|
|
|
|
from .models import Note
|
|
|
|
|
|
|
|
|
|
|
|
class NoteViewSet(viewsets.ModelViewSet):
|
2023-03-01 22:58:22 +08:00
|
|
|
permission_classes = [IsAuthenticated]
|
2023-02-24 00:13:44 +08:00
|
|
|
serializer_class = NoteSerializer
|
2023-03-01 22:58:22 +08:00
|
|
|
queryset = Note.objects.all()
|
|
|
|
|
|
|
|
def get_queryset(self):
|
|
|
|
user = self.request.user
|
|
|
|
queryset = Note.objects.filter(owner=user).order_by('date_created')
|
|
|
|
return queryset
|
2023-03-01 23:27:46 +08:00
|
|
|
|
|
|
|
def perform_create(self, serializer):
|
|
|
|
serializer.save(owner=self.request.user)
|