권주희

Merge branch 'feature/basic_api_setting' into 'develop'

기본 ViewSet 설정

- User, Group ViewSet 기본 설정

See merge request !1
......@@ -26,3 +26,4 @@ __pycache__
npm-debug.log*
yarn-debug.log*
yarn-error.log*
.idea
......
from django.contrib.auth.models import User, Group
from rest_framework import serializers
class UserSerializer(serializers.HyperlinkedModelSerializer):
class Meta:
model = User
fields = ['url', 'username', 'email', 'groups']
class GroupSerializer(serializers.HyperlinkedModelSerializer):
class Meta:
model = Group
fields = ['url', 'name']
\ No newline at end of file
from django.shortcuts import render
from django.contrib.auth.models import User, Group
from rest_framework import viewsets
from rest_framework import permissions
from khudrive.api.serializers import UserSerializer,GroupSerializer
# Create your views here.
class UserViewSet(viewsets.ModelViewSet):
"""
API endpoint that allows users to be viewed or edited.
"""
queryset = User.objects.all().order_by('-date_joined')
serializer_class = UserSerializer
permission_classes = [permissions.IsAuthenticated]
class ItemViewSet(viewsets.ModelViewSet):
"""
API endpoint that allows groups to be viewed or edited.
"""
queryset = Group.objects.all()
serializer_class = GroupSerializer
permission_classes = [permissions.IsAuthenticated]
\ No newline at end of file
......
......@@ -38,6 +38,7 @@ INSTALLED_APPS = [
'django.contrib.messages',
'django.contrib.staticfiles',
'rest_framework',
# 'api.apps.ApiConfig',
]
MIDDLEWARE = [
......
......@@ -13,9 +13,20 @@ Including another URLconf
1. Import the include() function: from django.urls import include, path
2. Add a URL to urlpatterns: path('blog/', include('blog.urls'))
"""
from django.urls import include, path
from rest_framework import routers
from khudrive.api import views
from django.contrib import admin
from django.urls import path
router = routers.DefaultRouter()
router.register(r'users', views.UserViewSet)
router.register(r'groups', views.ItemViewSet)
# Wire up our API using automatic URL routing.
# Additionally, we include login URLs for the browsable API.
urlpatterns = [
path('admin/', admin.site.urls),
]
path('', include(router.urls)),
path('api-auth/', include('rest_framework.urls', namespace='rest_framework'))
]
\ No newline at end of file
......