added bluetooth and camera serializers
This commit is contained in:
parent
2a78fa8262
commit
23a26eac10
3 changed files with 32 additions and 7 deletions
|
@ -1,10 +1,21 @@
|
||||||
from rest_framework import serializers
|
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 DeviceSerializer(serializers.HyperlinkedModelSerializer):
|
||||||
class Meta:
|
class Meta:
|
||||||
model = Device
|
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 = []
|
|
@ -1,10 +1,13 @@
|
||||||
from django.urls import include, path
|
from django.urls import include, path
|
||||||
from rest_framework import routers
|
from rest_framework import routers
|
||||||
|
|
||||||
from suitablephones.views import DeviceViewSet, SuitablePhones
|
from suitablephones.views import (BluetoothViewSet, CameraViewSet,
|
||||||
|
DeviceViewSet, SuitablePhones)
|
||||||
|
|
||||||
router = routers.DefaultRouter()
|
router = routers.DefaultRouter()
|
||||||
router.register(r'devices', DeviceViewSet)
|
router.register(r'devices', DeviceViewSet)
|
||||||
|
router.register(r'bluetooth', BluetoothViewSet)
|
||||||
|
router.register(r'camera', CameraViewSet)
|
||||||
|
|
||||||
urlpatterns = [
|
urlpatterns = [
|
||||||
path('api/', include(router.urls)),
|
path('api/', include(router.urls)),
|
||||||
|
|
|
@ -1,8 +1,9 @@
|
||||||
from django.views.generic.list import ListView
|
from django.views.generic.list import ListView
|
||||||
from rest_framework import viewsets
|
from rest_framework import viewsets
|
||||||
|
|
||||||
from suitablephones.models import Device
|
from suitablephones.models import Bluetooth, Camera, Device
|
||||||
from suitablephones.serializers import DeviceSerializer
|
from suitablephones.serializers import (BluetoothSerializer, CameraSerializer,
|
||||||
|
DeviceSerializer)
|
||||||
|
|
||||||
|
|
||||||
class SuitablePhones(ListView):
|
class SuitablePhones(ListView):
|
||||||
|
@ -20,4 +21,14 @@ class SuitablePhones(ListView):
|
||||||
# ViewSets define the view behavior.
|
# ViewSets define the view behavior.
|
||||||
class DeviceViewSet(viewsets.ModelViewSet):
|
class DeviceViewSet(viewsets.ModelViewSet):
|
||||||
queryset = Device.objects.all()
|
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
|
Loading…
Reference in a new issue