Toggle navigation
Toggle navigation
This project
Loading...
Sign in
2020-1-CloudComputing
/
C_Team_KhuDrive
Go to a project
Toggle navigation
Toggle navigation pinning
Projects
Groups
Snippets
Help
Project
Activity
Repository
Graphs
Network
Create a new issue
Commits
Issue Boards
Authored by
권주희
2020-05-20 16:55:31 +0900
Browse Files
Options
Browse Files
Download
Email Patches
Plain Diff
Commit
411effc7566f181a2354e782d9014e195242916a
411effc7
1 parent
ea416ad3
기본 ViewSet 설정
- User, Group ViewSet 기본 설정
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
48 additions
and
4 deletions
.gitignore
backend/khudrive/api/serializers.py
backend/khudrive/api/views.py
backend/khudrive/settings.py
backend/khudrive/urls.py
.gitignore
View file @
411effc
...
...
@@ -26,3 +26,4 @@ __pycache__
npm-debug.log*
yarn-debug.log*
yarn-error.log*
.idea
...
...
backend/khudrive/api/serializers.py
0 → 100644
View file @
411effc
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
backend/khudrive/api/views.py
View file @
411effc
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
...
...
backend/khudrive/settings.py
View file @
411effc
...
...
@@ -38,6 +38,7 @@ INSTALLED_APPS = [
'django.contrib.messages'
,
'django.contrib.staticfiles'
,
'rest_framework'
,
# 'api.apps.ApiConfig',
]
MIDDLEWARE
=
[
...
...
backend/khudrive/urls.py
View file @
411effc
...
...
@@ -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
...
...
Please
register
or
login
to post a comment