Commit 64582319 authored by ibuler's avatar ibuler

Add api file

parent 9a6d20b6
......@@ -48,6 +48,7 @@ INSTALLED_APPS = [
'ops.apps.OpsConfig',
'audits.apps.AuditsConfig',
'common.apps.CommonConfig',
'rest_framework',
'bootstrapform',
# 'django.contrib.admin',
'django.contrib.auth',
......@@ -166,4 +167,12 @@ AUTH_USER_MODEL = 'users.User'
BOOTSTRAP_COLUMN_COUNT = 11
# Init data or generate fake data source for development
FIXTURE_DIRS = [os.path.join(BASE_DIR, 'fixtures'), ]
\ No newline at end of file
FIXTURE_DIRS = [os.path.join(BASE_DIR, 'fixtures'), ]
REST_FRAMEWORK = {
# Use Django's standard `django.contrib.auth` permissions,
# or allow read-only access for unauthenticated users.
'DEFAULT_PERMISSION_CLASSES': [
'rest_framework.permissions.DjangoModelPermissionsOrAnonReadOnly'
],
}
\ No newline at end of file
......@@ -25,6 +25,10 @@ urlpatterns = [
# url(r'^admin/', admin.site.urls),
]
urlpatterns += [
url(r'^api/users/', include('users.api_urls')),
]
if settings.DEBUG:
urlpatterns += static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)
# ~*~ coding: utf-8 ~*~
#
#
from rest_framework import viewsets
from .serializers import UserSerializer
from .models import User, UserGroup, Role
class UserViewSet(viewsets.ModelViewSet):
queryset = User.objects.all()
serializer_class = UserSerializer
# -*- coding: utf-8 -*-
#
from django.conf.urls import url, include
from rest_framework import routers
from .api import UserViewSet
router = routers.DefaultRouter()
router.register(r'users', UserViewSet)
urlpatterns = [
url(r'v1/', include(router.urls)),
url(r'^api-auth/', include('rest_framework.urls', namespace='rest_framework'))
]
# -*- coding: utf-8 -*-
#
from rest_framework import serializers
from .models import Role, User, UserGroup
class UserSerializer(serializers.HyperlinkedModelSerializer):
class Meta:
model = User
fields = '__all__'
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