singledevice view
This commit is contained in:
parent
2519fe4cca
commit
7860dffce0
3 changed files with 14 additions and 4 deletions
|
@ -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()
|
||||
|
||||
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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):
|
||||
|
|
Loading…
Reference in a new issue