Start implementing new Duck API

This commit is contained in:
Gergely Polonkai 2015-05-28 00:33:19 +02:00
parent 720f9c9472
commit 414392a9cf
4 changed files with 33 additions and 1 deletions

10
api/serializers.py Normal file
View File

@ -0,0 +1,10 @@
# -*- coding: utf-8 -*-
from rest_framework import serializers
from booking.models import Duck
class DuckSerializer(serializers.HyperlinkedModelSerializer):
class Meta:
model = Duck
fields = ('url', 'name', 'color',)
view_name = 'api:duck-detail'

View File

@ -1,9 +1,19 @@
from django.conf.urls import patterns, url from django.conf.urls import patterns, url, include
from rest_framework import routers
from . import views from . import views
from . import viewsets
rest_router = routers.DefaultRouter()
rest_router.register(r'ducks', viewsets.DuckViewSet)
urlpatterns = patterns( urlpatterns = patterns(
'', '',
url(
r'^',
include(rest_router.urls)
),
url( url(
r'^duck/book/$', r'^duck/book/$',
views.duck_book, views.duck_book,

11
api/viewsets.py Normal file
View File

@ -0,0 +1,11 @@
# -*- coding: utf-8 -*-
from django.contrib.auth.models import User
from rest_framework import viewsets, permissions
from .serializers import DuckSerializer
from booking.models import Duck
class DuckViewSet(viewsets.ReadOnlyModelViewSet):
queryset = Duck.objects.all()
serializer_class = DuckSerializer

View File

@ -37,6 +37,7 @@ INSTALLED_APPS = (
'django.contrib.messages', 'django.contrib.messages',
'django.contrib.staticfiles', 'django.contrib.staticfiles',
'django_js_reverse', 'django_js_reverse',
'rest_framework',
'accounts', 'accounts',
'booking', 'booking',
'api', 'api',