mirror of
https://github.com/lemeow125/Django-NotesApp.git
synced 2024-11-17 14:39:25 +08:00
23 lines
737 B
Python
23 lines
737 B
Python
from rest_framework.permissions import IsAuthenticated
|
|
from rest_framework import viewsets, generics
|
|
from .serializers import NoteSerializer
|
|
from .models import Note
|
|
|
|
|
|
class NoteViewSet(viewsets.ModelViewSet):
|
|
permission_classes = [IsAuthenticated]
|
|
serializer_class = NoteSerializer
|
|
queryset = Note.objects.all()
|
|
|
|
def get_queryset(self):
|
|
user = self.request.user
|
|
queryset = Note.objects.filter(owner=user).order_by('date_created')
|
|
return queryset
|
|
|
|
def perform_create(self, serializer):
|
|
serializer.save(owner=self.request.user)
|
|
|
|
|
|
class PublicNoteViewSet(generics.ListAPIView):
|
|
serializer_class = NoteSerializer
|
|
queryset = Note.objects.filter(public=True)
|