Commit 3a8d0a64 authored by Rafal's avatar Rafal

add views

parent b235eda7
...@@ -37,6 +37,7 @@ INSTALLED_APPS = ( ...@@ -37,6 +37,7 @@ INSTALLED_APPS = (
'django.contrib.messages', 'django.contrib.messages',
'django.contrib.staticfiles', 'django.contrib.staticfiles',
'rest_framework', 'rest_framework',
'rest_framework.authtoken',
'Hub', 'Hub',
) )
...@@ -50,6 +51,19 @@ MIDDLEWARE_CLASSES = ( ...@@ -50,6 +51,19 @@ MIDDLEWARE_CLASSES = (
'django.middleware.clickjacking.XFrameOptionsMiddleware', 'django.middleware.clickjacking.XFrameOptionsMiddleware',
) )
REST_FRAMEWORK = {
'DEFAULT_PERMISSION_CLASSES': ('rest_framework.permissions.IsAuthenticated',),
'DEFAULT_FILTER_BACKENDS': ('rest_framework.filters.DjangoFilterBackend',),
'DEFAULT_AUTHENTICATION_CLASSES': (
'rest_framework.authentication.SessionAuthentication',
'rest_framework.authentication.TokenAuthentication',
),
'DEFAULT_PAGINATION_CLASS': 'rest_framework.pagination.LimitOffsetPagination',
'PAGE_SIZE': 10
}
ANONYMOUS_USER_ID = -1
ROOT_URLCONF = 'BeHub.urls' ROOT_URLCONF = 'BeHub.urls'
WSGI_APPLICATION = 'BeHub.wsgi.application' WSGI_APPLICATION = 'BeHub.wsgi.application'
......
from django.conf.urls import patterns, include, url from django.conf.urls import patterns, include, url
from django.contrib import admin from django.contrib import admin
from rest_framework import routers
from Hub import views as hub_views
router = routers.DefaultRouter()
router.register(r'beacons', hub_views.BeaconViewSet)
router.register(r'projects', hub_views.ProjectViewSet)
urlpatterns = patterns('', urlpatterns = patterns('',
# Examples: # Examples:
# url(r'^$', 'BeHub.views.home', name='home'), # url(r'^$', 'BeHub.views.home', name='home'),
# url(r'^blog/', include('blog.urls')), # url(r'^blog/', include('blog.urls')),
url(r'^api/', include(router.urls)),
url(r'^admin/', include(admin.site.urls)), url(r'^admin/', include(admin.site.urls)),
) )
from django.contrib import admin from django.contrib import admin
# Register your models here. # Register your models here.
from Hub.models import Beacon
from Hub.models import Project
admin.register(Beacon)
admin.register(Project)
\ No newline at end of file
...@@ -2,7 +2,6 @@ from django.db import models ...@@ -2,7 +2,6 @@ from django.db import models
# Create your models here. # Create your models here.
class Project(models.Model): class Project(models.Model):
link_url = models.CharField(max_length=2000) link_url = models.CharField(max_length=2000)
description = models.CharField(max_length=300, null=True) description = models.CharField(max_length=300, null=True)
......
from rest_framework import serializers from rest_framework import serializers
from models import Beacon from Hub.models import Beacon, Project
class BeaconSerializer(serializers.HyperlinkedModelSerializer): class BeaconSerializer(serializers.HyperlinkedModelSerializer):
class Meta: class Meta:
model = Beacon model = Beacon
fields = ('id', 'url', 'title', 'source_url', 'content', 'image', fields = ('id', 'url', 'uuid', 'name', 'project', 'description',)
'activities')
class ProjectSerializer(serializers.HyperlinkedModelSerializer):
class Meta:
model = Project
fields = ('id', 'url', 'link_url', 'description')
from django.shortcuts import render from django.shortcuts import render
# Create your views here. # Create your views here.
from rest_framework import viewsets
from Hub.models import Beacon, Project
from Hub.serializers import BeaconSerializer, ProjectSerializer
class BeaconViewSet(viewsets.ModelViewSet):
"""
API for places
"""
queryset = Beacon.objects.all()
serializer_class = BeaconSerializer
class ProjectViewSet(viewsets.ModelViewSet):
"""
API for places
"""
queryset = Project.objects.all()
serializer_class = ProjectSerializer
\ No newline at end of file
__author__ = 'Rafal'
__author__ = 'Rafal'
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