added bluetooth and camera serializers

This commit is contained in:
Matteo Parrucci 2023-01-03 12:02:23 +01:00
parent 2a78fa8262
commit 23a26eac10
3 changed files with 32 additions and 7 deletions

View file

@ -1,10 +1,21 @@
from rest_framework import serializers
from suitablephones.models import Device
from suitablephones.models import Bluetooth, Camera, Device
# Serializers define the API representation.
class DeviceSerializer(serializers.HyperlinkedModelSerializer):
class Meta:
model = Device
fields = ['cpu', 'kernel', 'name']
exclude = []
class CameraSerializer(serializers.HyperlinkedModelSerializer):
class Meta:
model = Camera
exclude = []
class BluetoothSerializer(serializers.HyperlinkedModelSerializer):
class Meta:
model = Bluetooth
exclude = []

View file

@ -1,10 +1,13 @@
from django.urls import include, path
from rest_framework import routers
from suitablephones.views import DeviceViewSet, SuitablePhones
from suitablephones.views import (BluetoothViewSet, CameraViewSet,
DeviceViewSet, SuitablePhones)
router = routers.DefaultRouter()
router.register(r'devices', DeviceViewSet)
router.register(r'bluetooth', BluetoothViewSet)
router.register(r'camera', CameraViewSet)
urlpatterns = [
path('api/', include(router.urls)),

View file

@ -1,8 +1,9 @@
from django.views.generic.list import ListView
from rest_framework import viewsets
from suitablephones.models import Device
from suitablephones.serializers import DeviceSerializer
from suitablephones.models import Bluetooth, Camera, Device
from suitablephones.serializers import (BluetoothSerializer, CameraSerializer,
DeviceSerializer)
class SuitablePhones(ListView):
@ -20,4 +21,14 @@ class SuitablePhones(ListView):
# ViewSets define the view behavior.
class DeviceViewSet(viewsets.ModelViewSet):
queryset = Device.objects.all()
serializer_class = DeviceSerializer
serializer_class = DeviceSerializer
class BluetoothViewSet(viewsets.ModelViewSet):
queryset = Bluetooth.objects.all()
serializer_class = BluetoothSerializer
class CameraViewSet(viewsets.ModelViewSet):
queryset = Camera.objects.all()
serializer_class = CameraSerializer