implement basic API GETs for countdown items

This commit is contained in:
Brian S. Stephan 2020-10-25 12:20:39 -05:00
parent a6f8fc5dc1
commit 9d94155f66
4 changed files with 44 additions and 3 deletions

14
countdown/serializers.py Normal file
View File

@ -0,0 +1,14 @@
"""REST serializers for countdown items."""
from rest_framework import serializers
from countdown.models import CountdownItem
class CountdownItemSerializer(serializers.ModelSerializer):
"""Countdown item serializer for the REST API."""
class Meta:
"""Meta options."""
model = CountdownItem
fields = '__all__'

12
countdown/urls.py Normal file
View File

@ -0,0 +1,12 @@
"""URL patterns for the countdown views."""
from django.conf.urls import include, url
from rest_framework.routers import DefaultRouter
from countdown.views import CountdownItemViewSet
router = DefaultRouter()
router.register(r'items', CountdownItemViewSet)
urlpatterns = [
url(r'^api/', include(router.urls)),
]

16
countdown/views.py Normal file
View File

@ -0,0 +1,16 @@
"""Provide an interface to countdown items."""
# from rest_framework.decorators import action
# from rest_framework.response import Response
from rest_framework.permissions import IsAuthenticated
from rest_framework.viewsets import ReadOnlyModelViewSet
from countdown.models import CountdownItem
from countdown.serializers import CountdownItemSerializer
class CountdownItemViewSet(ReadOnlyModelViewSet):
"""Provide list and detail actions for countdown items."""
queryset = CountdownItem.objects.all()
serializer_class = CountdownItemSerializer
permission_classes = [IsAuthenticated]

View File

@ -1,11 +1,9 @@
"""General/baselite/site-wide URLs."""
from adminplus.sites import AdminSitePlus
from django.conf.urls import include, url
from django.contrib import admin
from django.views.generic import TemplateView
from adminplus.sites import AdminSitePlus
admin.site = AdminSitePlus()
admin.sites.site = admin.site
admin.autodiscover()
@ -13,6 +11,7 @@ admin.autodiscover()
urlpatterns = [
url(r'^$', TemplateView.as_view(template_name='index.html'), name='index'),
url(r'^countdown/', include('countdown.urls')),
url(r'^dice/', include('dice.urls')),
url(r'^dispatch/', include('dispatch.urls')),
url(r'^itemsets/', include('facts.urls')),