Added Django Rest Framework, and a new app

This commit is contained in:
Tyrel Souza 2015-03-09 22:24:40 -04:00
parent 4d74c944e3
commit 6c6b0225a5
10 changed files with 49 additions and 6 deletions

0
project/__init__.py Normal file
View File

3
project/admin.py Normal file
View File

@ -0,0 +1,3 @@
from django.contrib import admin
# Register your models here.

View File

3
project/models.py Normal file
View File

@ -0,0 +1,3 @@
from django.db import models
# Create your models here.

3
project/tests.py Normal file
View File

@ -0,0 +1,3 @@
from django.test import TestCase
# Create your tests here.

3
project/views.py Normal file
View File

@ -0,0 +1,3 @@
from django.shortcuts import render
# Create your views here.

View File

@ -1,2 +1,5 @@
Django==1.7.6 Django==1.7.6
mysqlclient mysqlclient
djangorestframework
markdown
django-filter

7
roadmap/drf_settings.py Normal file
View File

@ -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'
]
}

View File

@ -16,6 +16,7 @@ INSTALLED_APPS = (
'django.contrib.sessions', 'django.contrib.sessions',
'django.contrib.messages', 'django.contrib.messages',
'django.contrib.staticfiles', 'django.contrib.staticfiles',
'rest_framework'
) )
@ -59,3 +60,5 @@ STATIC_URL = '/static/'
TEMPLATE_DIRS = ( TEMPLATE_DIRS = (
os.path.join(BASE_DIR, 'templates'), os.path.join(BASE_DIR, 'templates'),
) )
from drf_settings import *

View File

@ -1,10 +1,28 @@
from django.conf.urls import patterns, include, url from django.conf.urls import patterns, include, url
from django.contrib.auth.models import User
from django.contrib import admin 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('', 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'^admin/', include(admin.site.urls)),
url(r'^api/', include(router.urls)),
url(r'^api-auth/', include('rest_framework.urls', namespace='rest_framework'))
) )