Verified Commit 9bd6df09 authored by Kunal Sarkhel's avatar Kunal Sarkhel
Browse files

Add Report model, viewset, route, and serializer

parent de9ef825
......@@ -12,6 +12,7 @@ from __future__ import (absolute_import, division, print_function,
# Python stdlib Imports
import datetime
import uuid
# Django Imports
from django.db import models
......@@ -376,3 +377,28 @@ class Alert(TimeStampedModel):
String representation of an Alert object.
return "%s" % (self.message)
class Report(TimeStampedModel):
# DeviceID helps us identify which device sent us the request. This will help identify fraudulent reports.
deviceId = models.UUIDField(default=uuid.uuid4, editable=False)
# The platform the report was submitted from
('web', 'Web'),
('ios', 'iOS'),
('android', 'Android'),
('alexa', 'Alexa'),
('ghome', 'Google Home'),
('other', 'Other'),
platform = models.CharField(max_length=15, default='web', choices=PLATFORM_CHOICES)
# Which facility has incorrect hours?
facility = models.ForeignKey('Facility', related_name='facilities')
def __str__(self):
:return: string representation of a report object
return "Report: Facility={0}".format(self.facility)
......@@ -11,7 +11,7 @@ from __future__ import (absolute_import, division, print_function,
# App Imports
from .models import Category, Facility, Schedule, OpenTime, Location, Alert
from .models import Category, Facility, Schedule, OpenTime, Location, Alert, Report
# Other Imports
from rest_framework import serializers
......@@ -98,3 +98,22 @@ class FacilitySerializer(serializers.HyperlinkedModelSerializer):
'facility_product_tags', 'tapingo_url',
'main_schedule', 'special_schedules',
'modified', )
class ReportSerializer(serializers.HyperlinkedModelSerializer):
Serializer for the Report model.
From the docs:
The HyperlinkedModelSerializer class is similar to the ModelSerializer
class except that it uses hyperlinks to represent relationships, rather
than primary keys.
# Append a serialized Category object
facility = FacilitySerializer(many=False, read_only=True)
class Meta:
model = Report
fields = ('deviceId', 'platform', 'facility')
......@@ -15,7 +15,7 @@ from django.views.generic.base import RedirectView
# App Imports
from .views import (CategoryViewSet, FacilityViewSet, ScheduleViewSet,
LocationViewSet, AlertViewSet)
LocationViewSet, AlertViewSet, ReportViewSet)
# Other Imports
from rest_framework.routers import DefaultRouter
......@@ -29,6 +29,7 @@ ROUTER.register(r'categories', CategoryViewSet, 'category')
ROUTER.register(r'facilities', FacilityViewSet, 'facility')
ROUTER.register(r'locations', LocationViewSet, 'location')
ROUTER.register(r'schedules', ScheduleViewSet, 'schedule')
ROUTER.register(r'reports', ReportViewSet, 'report')
urlpatterns = [
# / - Default route
......@@ -14,10 +14,11 @@ from __future__ import (absolute_import, division, print_function,
import datetime
# App Imports
from .models import Facility, OpenTime, Category, Schedule, Location, Alert
from .models import Facility, OpenTime, Category, Schedule, Location, Alert, Report
from .serializers import (CategorySerializer, FacilitySerializer,
ScheduleSerializer, OpenTimeSerializer,
LocationSerializer, AlertSerializer)
LocationSerializer, AlertSerializer,
# Other Imports
from rest_framework import viewsets, filters
......@@ -531,3 +532,19 @@ class OpenTimeViewSet(viewsets.ModelViewSet):
the API.
return OpenTime.objects.all()
class ReportViewSet(viewsets.ModelViewSet):
Represents a report of incorrect hours.
# Associate a serializer with the ViewSet
serializer_class = ReportSerializer
def get_queryset(self):
Handle incoming GET requests and enumerate objects that get returned by
the API.
return Report.objects.all()
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