From 2519fe4cca29e175c271243aa876e7280a80a1c8 Mon Sep 17 00:00:00 2001 From: d0c Date: Wed, 22 Feb 2023 14:02:32 +0100 Subject: [PATCH] short queryset --- suitablephones/serializers.py | 2 +- suitablephones/views.py | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/suitablephones/serializers.py b/suitablephones/serializers.py index dbc2112..7a64475 100644 --- a/suitablephones/serializers.py +++ b/suitablephones/serializers.py @@ -31,4 +31,4 @@ class DeviceSerializer(serializers.ModelSerializer): class DeviceSerializerShort(DeviceSerializer): class Meta: model = Device - include = ["codename", "vendor", "name", "release", "maintainers", "cameras", "battery", "screen"] \ No newline at end of file + fields = ["codename", "vendor", "name", "versions", "maintainers", "cameras", "screen"] \ No newline at end of file diff --git a/suitablephones/views.py b/suitablephones/views.py index 65f0bfd..3533649 100644 --- a/suitablephones/views.py +++ b/suitablephones/views.py @@ -5,13 +5,13 @@ from rest_framework import viewsets from suitablephones.models import Bluetooth, Camera, Device from suitablephones.serializers import (BluetoothSerializer, CameraSerializer, - DeviceSerializer) + DeviceSerializer, DeviceSerializerShort) # ViewSets define the view behavior. class DeviceViewSet(viewsets.ModelViewSet): queryset = Device.objects.all() - serializer_class = DeviceSerializer + serializer_class = DeviceSerializerShort #http://url/api/devices?megapixel=3 def get_queryset(self): @@ -29,7 +29,7 @@ class DeviceViewSet(viewsets.ModelViewSet): if version: self.queryset = self.queryset.filter(versions__icontains=version) if size_in: - self.queryset = self.queryset.filter(screen__size_in__gt=Decimal(size_in)) + self.queryset = self.queryset.filter(screen__size_in__lt=Decimal(size_in)) if resolution: self.queryset = self.queryset.filter(screen__resolution__icontains=resolution) if screen_type: