diff --git a/suitablephones/management/commands/fetchphones.py b/suitablephones/management/commands/fetchphones.py index 8804dd5..7b33785 100644 --- a/suitablephones/management/commands/fetchphones.py +++ b/suitablephones/management/commands/fetchphones.py @@ -20,7 +20,7 @@ def set_screens(args): #if type(args) screen = Screen.objects.filter(**args) if not screen.exists(): - screen = Screens() + screen = Screen() for subkey, subvalue in args.items(): if subkey == 'size': size_mm = subvalue.split(' ')[0] @@ -134,4 +134,4 @@ class Command(BaseCommand): for scr in screen: dev.screen.add(scr) dev.save() - \ No newline at end of file + diff --git a/suitablephones/urls.py b/suitablephones/urls.py index 283581b..7067aa0 100644 --- a/suitablephones/urls.py +++ b/suitablephones/urls.py @@ -1,9 +1,10 @@ from django.urls import include, path from rest_framework import routers -from suitablephones.views import BluetoothViewSet, CameraViewSet, DeviceViewSet +from suitablephones.views import BluetoothViewSet, CameraViewSet, DeviceViewSet, SingleDeviceViewSet -router = routers.DefaultRouter() +router = routers.DefaultRouter(trailing_slash=False) +router.register(r'device', SingleDeviceViewSet) router.register(r'devices', DeviceViewSet) router.register(r'bluetooth', BluetoothViewSet) router.register(r'camera', CameraViewSet) diff --git a/suitablephones/views.py b/suitablephones/views.py index 3533649..88d99fd 100644 --- a/suitablephones/views.py +++ b/suitablephones/views.py @@ -7,6 +7,15 @@ from suitablephones.models import Bluetooth, Camera, Device from suitablephones.serializers import (BluetoothSerializer, CameraSerializer, DeviceSerializer, DeviceSerializerShort) +class SingleDeviceViewSet(viewsets.ModelViewSet): + queryset = Device.objects.all() + serializer_class = DeviceSerializer + + def get_queryset(self): + codename = self.request.query_params.get('codename') + if codename: + self.queryset = self.queryset.filter(codename__icontains=codename) + return self.queryset # ViewSets define the view behavior. class DeviceViewSet(viewsets.ModelViewSet):