Start implementing new Duck API
This commit is contained in:
parent
720f9c9472
commit
414392a9cf
10
api/serializers.py
Normal file
10
api/serializers.py
Normal 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'
|
12
api/urls.py
12
api/urls.py
@ -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
11
api/viewsets.py
Normal 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
|
@ -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',
|
||||||
|
Loading…
Reference in New Issue
Block a user