Merge branch 'feature/basic_api_setting' into 'develop'
기본 ViewSet 설정 - User, Group ViewSet 기본 설정 See merge request !1
Showing
5 changed files
with
47 additions
and
3 deletions
backend/khudrive/api/serializers.py
0 → 100644
1 | +from django.contrib.auth.models import User, Group | ||
2 | +from rest_framework import serializers | ||
3 | + | ||
4 | +class UserSerializer(serializers.HyperlinkedModelSerializer): | ||
5 | + class Meta: | ||
6 | + model = User | ||
7 | + fields = ['url', 'username', 'email', 'groups'] | ||
8 | + | ||
9 | +class GroupSerializer(serializers.HyperlinkedModelSerializer): | ||
10 | + class Meta: | ||
11 | + model = Group | ||
12 | + fields = ['url', 'name'] | ||
... | \ No newline at end of file | ... | \ No newline at end of file |
1 | -from django.shortcuts import render | 1 | +from django.contrib.auth.models import User, Group |
2 | +from rest_framework import viewsets | ||
3 | +from rest_framework import permissions | ||
4 | +from khudrive.api.serializers import UserSerializer,GroupSerializer | ||
2 | 5 | ||
3 | -# Create your views here. | 6 | + |
7 | +class UserViewSet(viewsets.ModelViewSet): | ||
8 | + """ | ||
9 | + API endpoint that allows users to be viewed or edited. | ||
10 | + """ | ||
11 | + queryset = User.objects.all().order_by('-date_joined') | ||
12 | + serializer_class = UserSerializer | ||
13 | + permission_classes = [permissions.IsAuthenticated] | ||
14 | + | ||
15 | + | ||
16 | +class ItemViewSet(viewsets.ModelViewSet): | ||
17 | + """ | ||
18 | + API endpoint that allows groups to be viewed or edited. | ||
19 | + """ | ||
20 | + queryset = Group.objects.all() | ||
21 | + serializer_class = GroupSerializer | ||
22 | + permission_classes = [permissions.IsAuthenticated] | ||
... | \ No newline at end of file | ... | \ No newline at end of file | ... | ... |
... | @@ -38,6 +38,7 @@ INSTALLED_APPS = [ | ... | @@ -38,6 +38,7 @@ INSTALLED_APPS = [ |
38 | 'django.contrib.messages', | 38 | 'django.contrib.messages', |
39 | 'django.contrib.staticfiles', | 39 | 'django.contrib.staticfiles', |
40 | 'rest_framework', | 40 | 'rest_framework', |
41 | + # 'api.apps.ApiConfig', | ||
41 | ] | 42 | ] |
42 | 43 | ||
43 | MIDDLEWARE = [ | 44 | MIDDLEWARE = [ | ... | ... |
... | @@ -13,9 +13,20 @@ Including another URLconf | ... | @@ -13,9 +13,20 @@ Including another URLconf |
13 | 1. Import the include() function: from django.urls import include, path | 13 | 1. Import the include() function: from django.urls import include, path |
14 | 2. Add a URL to urlpatterns: path('blog/', include('blog.urls')) | 14 | 2. Add a URL to urlpatterns: path('blog/', include('blog.urls')) |
15 | """ | 15 | """ |
16 | + | ||
17 | +from django.urls import include, path | ||
18 | +from rest_framework import routers | ||
19 | +from khudrive.api import views | ||
16 | from django.contrib import admin | 20 | from django.contrib import admin |
17 | -from django.urls import path | ||
18 | 21 | ||
22 | +router = routers.DefaultRouter() | ||
23 | +router.register(r'users', views.UserViewSet) | ||
24 | +router.register(r'groups', views.ItemViewSet) | ||
25 | + | ||
26 | +# Wire up our API using automatic URL routing. | ||
27 | +# Additionally, we include login URLs for the browsable API. | ||
19 | urlpatterns = [ | 28 | urlpatterns = [ |
20 | path('admin/', admin.site.urls), | 29 | path('admin/', admin.site.urls), |
30 | + path('', include(router.urls)), | ||
31 | + path('api-auth/', include('rest_framework.urls', namespace='rest_framework')) | ||
21 | ] | 32 | ] |
... | \ No newline at end of file | ... | \ No newline at end of file | ... | ... |
-
Please register or login to post a comment