diff --git a/suitablephones/serializers.py b/suitablephones/serializers.py index cc10c8a..0f06ccf 100644 --- a/suitablephones/serializers.py +++ b/suitablephones/serializers.py @@ -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'] \ No newline at end of file + exclude = [] + + +class CameraSerializer(serializers.HyperlinkedModelSerializer): + class Meta: + model = Camera + exclude = [] + + +class BluetoothSerializer(serializers.HyperlinkedModelSerializer): + class Meta: + model = Bluetooth + exclude = [] \ No newline at end of file diff --git a/suitablephones/urls.py b/suitablephones/urls.py index f4b7629..c077360 100644 --- a/suitablephones/urls.py +++ b/suitablephones/urls.py @@ -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)), diff --git a/suitablephones/views.py b/suitablephones/views.py index 2ce64f7..033caeb 100644 --- a/suitablephones/views.py +++ b/suitablephones/views.py @@ -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 \ No newline at end of file + 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 \ No newline at end of file