Commit 8aa92bb6 authored by ibuler's avatar ibuler

Add api: UserApi And UserGroupApi

parent 1d5faa31
# ~*~ coding: utf-8 ~*~
#
from rest_framework import generics
from rest_framework import mixins
from rest_framework import generics, mixins, status, permissions
from rest_framework.views import APIView
from rest_framework.response import Response
from .serializers import UserSerializer
from .serializers import UserSerializer, UserGroupSerializer
from .models import User, UserGroup
class UserListApi(generics.ListCreateAPIView):
class UserListAddApi(generics.ListCreateAPIView):
queryset = User.objects.all()
serializer_class = UserSerializer
class UserDetailApi(generics.RetrieveUpdateDestroyAPIView):
class UserDetailDeleteUpdateApi(generics.RetrieveUpdateDestroyAPIView):
queryset = User.objects.all()
serializer_class = UserSerializer
class UserGroupListAddApi(generics.ListCreateAPIView):
queryset = UserGroup.objects.all()
serializer_class = UserGroupSerializer
class UserGroupDetailDeleteUpdateApi(generics.RetrieveUpdateDestroyAPIView):
queryset = UserGroup.objects.all()
serializer_class = UserGroupSerializer
......@@ -2,11 +2,12 @@
#
from django.conf.urls import url, include
from .api import UserListApi, UserDetailApi
import api
urlpatterns = [
url(r'^v1/users/$', UserListApi.as_view()),
url(r'^v1/users/(?P<pk>[0-9]+)/$', UserDetailApi.as_view()),
url(r'^v1/users/$', api.UserListAddApi.as_view(), name='user-list-api'),
url(r'^v1/users/(?P<pk>[0-9]+)/$', api.UserDetailDeleteUpdateApi.as_view(), name='user-detail-api'),
url(r'^v1/usergroups/$', api.UserGroupListAddApi.as_view(), name='usergroup-list-api'),
url(r'^v1/usergroups/(?P<pk>[0-9]+)/$', api.UserGroupDetailDeleteUpdateApi.as_view(),
name='usergroup-detail-api'),
]
......@@ -10,8 +10,8 @@ class UserSerializer(serializers.ModelSerializer):
class Meta:
model = User
exclude = [
'password', 'first_name', 'last_name', 'is_staff', 'secret_key_otp',
'private_key', 'public_key',
'password', 'first_name', 'last_name', 'secret_key_otp',
'private_key', 'public_key', 'avatar',
]
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment