short queryset

This commit is contained in:
d0c 2023-02-22 14:02:32 +01:00
parent 5502be73bb
commit 2519fe4cca
2 changed files with 4 additions and 4 deletions

View file

@ -31,4 +31,4 @@ class DeviceSerializer(serializers.ModelSerializer):
class DeviceSerializerShort(DeviceSerializer): class DeviceSerializerShort(DeviceSerializer):
class Meta: class Meta:
model = Device model = Device
include = ["codename", "vendor", "name", "release", "maintainers", "cameras", "battery", "screen"] fields = ["codename", "vendor", "name", "versions", "maintainers", "cameras", "screen"]

View file

@ -5,13 +5,13 @@ from rest_framework import viewsets
from suitablephones.models import Bluetooth, Camera, Device from suitablephones.models import Bluetooth, Camera, Device
from suitablephones.serializers import (BluetoothSerializer, CameraSerializer, from suitablephones.serializers import (BluetoothSerializer, CameraSerializer,
DeviceSerializer) DeviceSerializer, DeviceSerializerShort)
# 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 = DeviceSerializerShort
#http://url/api/devices?megapixel=3 #http://url/api/devices?megapixel=3
def get_queryset(self): def get_queryset(self):
@ -29,7 +29,7 @@ class DeviceViewSet(viewsets.ModelViewSet):
if version: if version:
self.queryset = self.queryset.filter(versions__icontains=version) self.queryset = self.queryset.filter(versions__icontains=version)
if size_in: 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: if resolution:
self.queryset = self.queryset.filter(screen__resolution__icontains=resolution) self.queryset = self.queryset.filter(screen__resolution__icontains=resolution)
if screen_type: if screen_type: