mirror of
https://github.com/daniviga/bite.git
synced 2024-11-30 00:26:13 +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'))
|
2. Add a URL to urlpatterns: path('blog/', include('blog.urls'))
|
||||||
"""
|
"""
|
||||||
from django.urls import path
|
from django.urls import path
|
||||||
from telemetry.views import Telemetry
|
from telemetry.views import TelemetryView
|
||||||
|
|
||||||
urlpatterns = [
|
urlpatterns = [
|
||||||
path('',
|
path('',
|
||||||
Telemetry.as_view({'get': 'list', 'post': 'create'}),
|
TelemetryView.as_view({'post': 'create'}),
|
||||||
name='telemetry'),
|
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 rest_framework.viewsets import ModelViewSet
|
||||||
|
|
||||||
from telemetry.models import Telemetry
|
from telemetry.models import Telemetry
|
||||||
from telemetry.serializers import TelemetrySerializer
|
from telemetry.serializers import TelemetrySerializer
|
||||||
|
from rest_framework.response import Response
|
||||||
|
|
||||||
|
|
||||||
class Telemetry(ModelViewSet):
|
class TelemetryView(ModelViewSet):
|
||||||
queryset = Telemetry.objects.all()
|
queryset = Telemetry.objects.all()
|
||||||
serializer_class = TelemetrySerializer
|
serializer_class = TelemetrySerializer
|
||||||
|
|
||||||
# def post(self, request):
|
def list(self, request, device=None):
|
||||||
# serializer = DeviceSerializer(data=request.data)
|
queryset = Telemetry.objects.filter(device__serial=device)
|
||||||
# if serializer.is_valid():
|
if not queryset:
|
||||||
# serializer.save()
|
raise Http404
|
||||||
# return Response(serializer.data, status=status.HTTP_201_CREATED)
|
serializer = TelemetrySerializer(queryset, many=True)
|
||||||
# return Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST)
|
return Response(serializer.data)
|
||||||
|
|
||||||
# def get(self, request):
|
|
||||||
# devices = Device.objects.all()
|
|
||||||
# import pdb; pdb.set_trace()
|
|
||||||
# serializer = DeviceSerializer(devices)
|
|
||||||
# return Response(serializer.serial)
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user