Added Django Rest Framework, and a new app
This commit is contained in:
parent
4d74c944e3
commit
6c6b0225a5
0
project/__init__.py
Normal file
0
project/__init__.py
Normal file
3
project/admin.py
Normal file
3
project/admin.py
Normal file
@ -0,0 +1,3 @@
|
||||
from django.contrib import admin
|
||||
|
||||
# Register your models here.
|
0
project/migrations/__init__.py
Normal file
0
project/migrations/__init__.py
Normal file
3
project/models.py
Normal file
3
project/models.py
Normal file
@ -0,0 +1,3 @@
|
||||
from django.db import models
|
||||
|
||||
# Create your models here.
|
3
project/tests.py
Normal file
3
project/tests.py
Normal file
@ -0,0 +1,3 @@
|
||||
from django.test import TestCase
|
||||
|
||||
# Create your tests here.
|
3
project/views.py
Normal file
3
project/views.py
Normal file
@ -0,0 +1,3 @@
|
||||
from django.shortcuts import render
|
||||
|
||||
# Create your views here.
|
@ -1,2 +1,5 @@
|
||||
Django==1.7.6
|
||||
mysqlclient
|
||||
djangorestframework
|
||||
markdown
|
||||
django-filter
|
7
roadmap/drf_settings.py
Normal file
7
roadmap/drf_settings.py
Normal 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'
|
||||
]
|
||||
}
|
@ -16,6 +16,7 @@ INSTALLED_APPS = (
|
||||
'django.contrib.sessions',
|
||||
'django.contrib.messages',
|
||||
'django.contrib.staticfiles',
|
||||
'rest_framework'
|
||||
)
|
||||
|
||||
|
||||
@ -59,3 +60,5 @@ STATIC_URL = '/static/'
|
||||
TEMPLATE_DIRS = (
|
||||
os.path.join(BASE_DIR, 'templates'),
|
||||
)
|
||||
|
||||
from drf_settings import *
|
@ -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'))
|
||||
)
|
||||
|
Loading…
Reference in New Issue
Block a user