Fakultas Ilmu Komputer UI

Commit cae33823 authored by Zamil Majdy's avatar Zamil Majdy
Browse files

Setup PostgreSQL and REST API

parent 9249d504
......@@ -33,6 +33,7 @@ INSTALLED_APPS = [
'django.contrib.staticfiles',
'webpack_loader',
'core',
'rest_framework'
]
MIDDLEWARE = [
......@@ -71,8 +72,12 @@ WSGI_APPLICATION = 'kape.wsgi.application'
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.sqlite3',
'NAME': os.path.join(BASE_DIR, 'db.sqlite3'),
'ENGINE': 'django.db.backends.postgresql_psycopg2',
'NAME': 'kape',
'USER': 'postgres',
'PASSWORD': 'hue',
'HOST': 'localhost',
'PORT': '',
}
}
......@@ -114,3 +119,11 @@ USE_TZ = True
# https://docs.djangoproject.com/en/1.10/howto/static-files/
STATIC_URL = '/static/'
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
......@@ -15,9 +15,15 @@ Including another URLconf
"""
from django.conf.urls import url, include
from django.contrib import admin
from rest_framework import routers
from kape.views.user import UserViewSet
router = routers.DefaultRouter()
router.register(r'users', UserViewSet)
urlpatterns = [
url(r"^api/", include(router.urls)),
url(r'^admin/', admin.site.urls),
url(r'', include('core.urls')),
url(r'^api/api-auth/', include('rest_framework.urls', namespace='rest_framework'))
]
from django.contrib.auth.models import User
from rest_framework import serializers, viewsets
# Serializers define the API representation.
class UserSerializer(serializers.HyperlinkedModelSerializer):
class Meta:
model = User
fields = ('url', 'username', 'email', 'is_staff')
# ViewSets define the view behavior.
class UserViewSet(viewsets.ModelViewSet):
queryset = User.objects.all()
serializer_class = UserSerializer
......@@ -3,5 +3,6 @@ Django==1.10.5
django-webpack-loader==0.4.1
djangorestframework==3.5.4
packaging==16.8
psycopg2==2.6.2
pyparsing==2.1.10
six==1.10.0
\ No newline at end of file
Supports Markdown
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