1
0
mirror of https://github.com/daniviga/bite.git synced 2024-12-23 08:41:24 +01:00

Telemetry is a POST only and filter GET by device (#9)

This commit is contained in:
Daniele Viganò 2020-06-05 00:15:31 +02:00 committed by GitHub
parent 973ca2decb
commit 253411c0fd
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 14 additions and 15 deletions

View File

@ -14,10 +14,13 @@ Including another URLconf
2. Add a URL to urlpatterns: path('blog/', include('blog.urls'))
"""
from django.urls import path
from telemetry.views import Telemetry
from telemetry.views import TelemetryView
urlpatterns = [
path('',
Telemetry.as_view({'get': 'list', 'post': 'create'}),
TelemetryView.as_view({'post': 'create'}),
name='telemetry'),
path('<str:device>/',
TelemetryView.as_view({'get': 'list'}),
name='device-telemetry'),
]

View File

@ -1,22 +1,18 @@
from django.http import Http404
from rest_framework.viewsets import ModelViewSet
from telemetry.models import Telemetry
from telemetry.serializers import TelemetrySerializer
from rest_framework.response import Response
class Telemetry(ModelViewSet):
class TelemetryView(ModelViewSet):
queryset = Telemetry.objects.all()
serializer_class = TelemetrySerializer
# def post(self, request):
# serializer = DeviceSerializer(data=request.data)
# if serializer.is_valid():
# serializer.save()
# return Response(serializer.data, status=status.HTTP_201_CREATED)
# return Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST)
# def get(self, request):
# devices = Device.objects.all()
# import pdb; pdb.set_trace()
# serializer = DeviceSerializer(devices)
# return Response(serializer.serial)
def list(self, request, device=None):
queryset = Telemetry.objects.filter(device__serial=device)
if not queryset:
raise Http404
serializer = TelemetrySerializer(queryset, many=True)
return Response(serializer.data)