Install and use djangorestframework
This commit is contained in:
0
apiv1/__init__.py
Normal file
0
apiv1/__init__.py
Normal file
3
apiv1/admin.py
Normal file
3
apiv1/admin.py
Normal file
@@ -0,0 +1,3 @@
|
||||
from django.contrib import admin
|
||||
|
||||
# Register your models here.
|
||||
5
apiv1/apps.py
Normal file
5
apiv1/apps.py
Normal file
@@ -0,0 +1,5 @@
|
||||
from django.apps import AppConfig
|
||||
|
||||
|
||||
class Apiv1Config(AppConfig):
|
||||
name = 'apiv1'
|
||||
0
apiv1/migrations/__init__.py
Normal file
0
apiv1/migrations/__init__.py
Normal file
7
apiv1/models.py
Normal file
7
apiv1/models.py
Normal file
@@ -0,0 +1,7 @@
|
||||
from rest_framework import serializers
|
||||
from bookmarks.models import Bookmark
|
||||
|
||||
class BookmarkSerializer(serializers.HyperlinkedModelSerializer):
|
||||
class Meta:
|
||||
model = Bookmark
|
||||
fields = ['title', 'url']
|
||||
3
apiv1/tests.py
Normal file
3
apiv1/tests.py
Normal file
@@ -0,0 +1,3 @@
|
||||
from django.test import TestCase
|
||||
|
||||
# Create your tests here.
|
||||
13
apiv1/urls.py
Normal file
13
apiv1/urls.py
Normal file
@@ -0,0 +1,13 @@
|
||||
from django.urls import include, path
|
||||
from rest_framework import routers
|
||||
from . import views
|
||||
|
||||
router = routers.DefaultRouter()
|
||||
router.register(r'bookmarks', views.BookmarkViewSet)
|
||||
|
||||
# Wire up our API using automatic URL routing.
|
||||
# Additionally, we include login URLs for the browsable API.
|
||||
urlpatterns = [
|
||||
path('', include(router.urls)),
|
||||
path('api-auth/', include('rest_framework.urls', namespace='rest_framework'))
|
||||
]
|
||||
8
apiv1/views.py
Normal file
8
apiv1/views.py
Normal file
@@ -0,0 +1,8 @@
|
||||
from rest_framework import viewsets
|
||||
|
||||
from . import models
|
||||
from bookmarks.models import Bookmark
|
||||
|
||||
class BookmarkViewSet(viewsets.ModelViewSet):
|
||||
queryset = Bookmark.objects.all()
|
||||
serializer_class = models.BookmarkSerializer
|
||||
Reference in New Issue
Block a user