mirror of
https://github.com/daniviga/bite.git
synced 2024-11-22 21:16:12 +01:00
Telemetry is a POST only and filter GET by device (#9)
This commit is contained in:
parent
973ca2decb
commit
253411c0fd
|
@ -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'),
|
||||
]
|
||||
|
|
|
@ -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)
|
||||
|
|
Loading…
Reference in New Issue
Block a user