Fix bookmarks api routes

This commit is contained in:
2021-04-01 21:01:42 -05:00
parent da85e74860
commit 0793242dfe
3 changed files with 10 additions and 3 deletions

View File

@@ -3,7 +3,7 @@ from rest_framework import routers
from . import views from . import views
router = routers.DefaultRouter() router = routers.DefaultRouter()
router.register(r'bookmarks', views.BookmarkViewSet) router.register(r'bookmarks', views.BookmarkViewSet, basename='bookmark')
# Wire up our API using automatic URL routing. # Wire up our API using automatic URL routing.
# Additionally, we include login URLs for the browsable API. # Additionally, we include login URLs for the browsable API.

View File

@@ -4,5 +4,10 @@ from . import models
from bookmarks.models import Bookmark from bookmarks.models import Bookmark
class BookmarkViewSet(viewsets.ModelViewSet): class BookmarkViewSet(viewsets.ModelViewSet):
queryset = Bookmark.objects.all()
serializer_class = models.BookmarkSerializer serializer_class = models.BookmarkSerializer
def perform_create(self, serializer):
serializer.save(user = self.request.user)
def get_queryset(self):
return Bookmark.objects.filter(user=self.request.user)

View File

@@ -129,5 +129,7 @@ REST_FRAMEWORK = {
# or allow read-only access for unauthenticated users. # or allow read-only access for unauthenticated users.
'DEFAULT_PERMISSION_CLASSES': [ 'DEFAULT_PERMISSION_CLASSES': [
'rest_framework.permissions.DjangoModelPermissionsOrAnonReadOnly' 'rest_framework.permissions.DjangoModelPermissionsOrAnonReadOnly'
] ],
'DEFAULT_PAGINATION_CLASS': 'rest_framework.pagination.PageNumberPagination',
'PAGE_SIZE': 100
} }