urls.py 1.08 KB
Newer Older
David Haynes's avatar
David Haynes committed
1
2
#!/usr/bin/env python
# -*- coding: utf-8 -*-
3
4
5
6
7
8
9
"""
api/urls.py

Define the routes that the API will serve content through.

http://www.django-rest-framework.org/api-guide/routers/
"""
10
# Django Imports
David Haynes's avatar
David Haynes committed
11
from django.urls import include, path
12
from django.views.generic.base import RedirectView
13
14

# App Imports
15
from .views import (CategoryViewSet, FacilityViewSet, ScheduleViewSet,
David Haynes's avatar
David Haynes committed
16
                    LocationViewSet, AlertViewSet)
17
18

# Other Imports
19
20
from rest_framework.routers import DefaultRouter

21
# Instantiate our DefaultRouter
22
23
24
ROUTER = DefaultRouter()

# Register views to the API router
David Haynes's avatar
David Haynes committed
25
ROUTER.register(r'alerts', AlertViewSet, 'alert')
David Haynes's avatar
David Haynes committed
26
27
28
ROUTER.register(r'categories', CategoryViewSet, 'category')
ROUTER.register(r'facilities', FacilityViewSet, 'facility')
ROUTER.register(r'locations', LocationViewSet, 'location')
David Haynes's avatar
David Haynes committed
29
ROUTER.register(r'schedules', ScheduleViewSet, 'schedule')
Daniel Bond's avatar
Daniel Bond committed
30

31
urlpatterns = [
32
33
    # / - Default route
    # We redirect to /api since this is in reality the default page for the API
David Haynes's avatar
David Haynes committed
34
    path('', RedirectView.as_view(url='/api')),
35
    # /api - Root API URL
David Haynes's avatar
David Haynes committed
36
    path('api/', include(ROUTER.urls)),
37
]