From 6c6b0225a5c7eca2f81650758ffb54ecd61c5657 Mon Sep 17 00:00:00 2001 From: Tyrel Souza Date: Mon, 9 Mar 2015 22:24:40 -0400 Subject: [PATCH] Added Django Rest Framework, and a new app --- project/__init__.py | 0 project/admin.py | 3 +++ project/migrations/__init__.py | 0 project/models.py | 3 +++ project/tests.py | 3 +++ project/views.py | 3 +++ requirements.txt | 5 ++++- roadmap/drf_settings.py | 7 +++++++ roadmap/settings.py | 5 ++++- roadmap/urls.py | 26 ++++++++++++++++++++++---- 10 files changed, 49 insertions(+), 6 deletions(-) create mode 100644 project/__init__.py create mode 100644 project/admin.py create mode 100644 project/migrations/__init__.py create mode 100644 project/models.py create mode 100644 project/tests.py create mode 100644 project/views.py create mode 100644 roadmap/drf_settings.py diff --git a/project/__init__.py b/project/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/project/admin.py b/project/admin.py new file mode 100644 index 0000000..8c38f3f --- /dev/null +++ b/project/admin.py @@ -0,0 +1,3 @@ +from django.contrib import admin + +# Register your models here. diff --git a/project/migrations/__init__.py b/project/migrations/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/project/models.py b/project/models.py new file mode 100644 index 0000000..71a8362 --- /dev/null +++ b/project/models.py @@ -0,0 +1,3 @@ +from django.db import models + +# Create your models here. diff --git a/project/tests.py b/project/tests.py new file mode 100644 index 0000000..7ce503c --- /dev/null +++ b/project/tests.py @@ -0,0 +1,3 @@ +from django.test import TestCase + +# Create your tests here. diff --git a/project/views.py b/project/views.py new file mode 100644 index 0000000..91ea44a --- /dev/null +++ b/project/views.py @@ -0,0 +1,3 @@ +from django.shortcuts import render + +# Create your views here. diff --git a/requirements.txt b/requirements.txt index b690c9c..3404ad0 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,2 +1,5 @@ Django==1.7.6 -mysqlclient \ No newline at end of file +mysqlclient +djangorestframework +markdown +django-filter \ No newline at end of file diff --git a/roadmap/drf_settings.py b/roadmap/drf_settings.py new file mode 100644 index 0000000..071c184 --- /dev/null +++ b/roadmap/drf_settings.py @@ -0,0 +1,7 @@ +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 diff --git a/roadmap/settings.py b/roadmap/settings.py index 5c2f152..3c204e4 100644 --- a/roadmap/settings.py +++ b/roadmap/settings.py @@ -16,6 +16,7 @@ INSTALLED_APPS = ( 'django.contrib.sessions', 'django.contrib.messages', 'django.contrib.staticfiles', + 'rest_framework' ) @@ -58,4 +59,6 @@ STATIC_URL = '/static/' TEMPLATE_DIRS = ( os.path.join(BASE_DIR, 'templates'), -) \ No newline at end of file +) + +from drf_settings import * \ No newline at end of file diff --git a/roadmap/urls.py b/roadmap/urls.py index b46c0fe..931714a 100644 --- a/roadmap/urls.py +++ b/roadmap/urls.py @@ -1,10 +1,28 @@ from django.conf.urls import patterns, include, url +from django.contrib.auth.models import User from django.contrib import admin +from rest_framework import routers, 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 + +# Routers provide an easy way of automatically determining the URL conf. +router = routers.DefaultRouter() +router.register(r'users', UserViewSet) + + + urlpatterns = patterns('', - # Examples: - # url(r'^$', 'roadmap.views.home', name='home'), - # url(r'^blog/', include('blog.urls')), - url(r'^admin/', include(admin.site.urls)), + url(r'^api/', include(router.urls)), + url(r'^api-auth/', include('rest_framework.urls', namespace='rest_framework')) )