File tree Expand file tree Collapse file tree 6 files changed +55
-20
lines changed Expand file tree Collapse file tree 6 files changed +55
-20
lines changed Original file line number Diff line number Diff line change
1
+ from rest_framework_json_api import serializers , relations
2
+ from accounts .models import User
3
+
4
+
5
+ class UserSerializer (serializers .ModelSerializer ):
6
+ class Meta :
7
+ model = User
8
+ fields = ('username' ,)
Original file line number Diff line number Diff line change
1
+ from django .conf .urls import url , include
2
+ from accounts import views
3
+ from rest_framework import routers
4
+
5
+
6
+ router = routers .DefaultRouter (trailing_slash = False )
7
+ router .register (r'users' , views .UserViewSet , base_name = 'User' )
8
+
9
+ urlpatterns = [
10
+ url (r'^' , include (router .urls )),
11
+ ]
Original file line number Diff line number Diff line change 1
- from django .shortcuts import render
1
+ from rest_framework import viewsets
2
+ from accounts .models import User
3
+ from accounts .serializers import UserSerializer
2
4
3
- # Create your views here.
5
+ class UserViewSet (viewsets .ModelViewSet ):
6
+ queryset = User .objects .all ()
7
+ serializer_class = UserSerializer
Original file line number Diff line number Diff line change 104
104
},
105
105
]
106
106
107
+ REST_FRAMEWORK = {
108
+ 'PAGE_SIZE' : 100 ,
109
+ 'EXCEPTION_HANDLER' : 'rest_framework_json_api.exceptions.exception_handler' ,
110
+ 'DEFAULT_PARSER_CLASSES' : (
111
+ 'rest_framework_json_api.parsers.JSONParser' ,
112
+ 'rest_framework.parsers.FormParser' ,
113
+ 'rest_framework.parsers.MultiPartParser' ,
114
+ 'rest_framework.parsers.JSONParser' ,
115
+ ),
116
+ 'DEFAULT_RENDERER_CLASSES' : (
117
+ 'rest_framework_json_api.renderers.JSONRenderer' ,
118
+ 'rest_framework.renderers.BrowsableAPIRenderer' ,
119
+ ),
120
+ 'DEFAULT_METADATA_CLASS' : 'rest_framework_json_api.metadata.JSONAPIMetadata' ,
121
+ 'TEST_REQUEST_DEFAULT_FORMAT' : 'json' ,
122
+ }
123
+
124
+ JSON_API_FORMAT_KEYS = 'underscore'
125
+ JSON_API_FORMAT_TYPES = 'underscore'
126
+ JSON_API_PLURALIZE_TYPES = True
127
+ JSON_API_PLURALIZE_RELATION_TYPE = True
128
+ JSON_API_FORMAT_RELATION_KEYS = True
107
129
108
130
# Internationalization
109
131
# https://docs.djangoproject.com/en/2.1/topics/i18n/
Original file line number Diff line number Diff line change 1
- """api URL Configuration
2
-
3
- The `urlpatterns` list routes URLs to views. For more information please see:
4
- https://docs.djangoproject.com/en/2.1/topics/http/urls/
5
- Examples:
6
- Function views
7
- 1. Add an import: from my_app import views
8
- 2. Add a URL to urlpatterns: path('', views.home, name='home')
9
- Class-based views
10
- 1. Add an import: from other_app.views import Home
11
- 2. Add a URL to urlpatterns: path('', Home.as_view(), name='home')
12
- Including another URLconf
13
- 1. Import the include() function: from django.urls import include, path
14
- 2. Add a URL to urlpatterns: path('blog/', include('blog.urls'))
15
- """
1
+ from django .conf .urls import url , include
16
2
from django .contrib import admin
17
- from django .urls import path
3
+
4
+ admin_root_url = r'^services/admin/'
18
5
19
6
urlpatterns = [
20
- path ('admin/' , admin .site .urls ),
7
+ url (admin_root_url , admin .site .urls ),
8
+ url (r'^services/api/' , include ('accounts.urls' )),
21
9
]
Original file line number Diff line number Diff line change 1
1
Django == 2.1.2
2
- psycopg2-binary == 2.7.5
2
+ psycopg2-binary == 2.7.5
3
+ djangorestframework == 3.8.2
4
+ djangorestframework-jsonapi == 2.2.0
You can’t perform that action at this time.
0 commit comments