search and architecture
This commit is contained in:
parent
58f19486e8
commit
ca5c5b93f4
5 changed files with 29 additions and 14 deletions
7
start.sh
Executable file
7
start.sh
Executable file
|
@ -0,0 +1,7 @@
|
||||||
|
#!/bin/bash
|
||||||
|
|
||||||
|
source bin/activate
|
||||||
|
pip install -r requirements.txt
|
||||||
|
docker compose up -d
|
||||||
|
python manage.py migrate
|
||||||
|
python manage.py runserver
|
|
@ -81,15 +81,12 @@ class Command(BaseCommand):
|
||||||
data = yaml.safe_load(stream)
|
data = yaml.safe_load(stream)
|
||||||
print(data['codename'])
|
print(data['codename'])
|
||||||
for key, value in data.items():
|
for key, value in data.items():
|
||||||
|
if key == "architecture":
|
||||||
# if key == "architecture":
|
if type(value) == str:
|
||||||
# if type(value) == dict():
|
setattr(dev, key, dict({ 'cpu' : value }))
|
||||||
# setattr(dev, key, value)
|
else:
|
||||||
# else: #type(value) == str():
|
for k,v in value.items():
|
||||||
# setattr(dev, key, dict({ 'cpu' : value }))
|
setattr(dev, key, dict({ k : v }))
|
||||||
#match caso:
|
|
||||||
# case dict():
|
|
||||||
# print('dict')
|
|
||||||
if key == "bluetooth":
|
if key == "bluetooth":
|
||||||
if not 'profiles' in value.keys():
|
if not 'profiles' in value.keys():
|
||||||
value['profiles'] = None
|
value['profiles'] = None
|
||||||
|
|
|
@ -34,7 +34,7 @@ class Screen(models.Model):
|
||||||
return f"{str(self.size_in)} - {str(self.density)} - {str(self.technology)}"
|
return f"{str(self.size_in)} - {str(self.density)} - {str(self.technology)}"
|
||||||
|
|
||||||
class Device(models.Model):
|
class Device(models.Model):
|
||||||
#architecture = models.JSONField(default=dict)
|
architecture = models.JSONField(default=dict)
|
||||||
#battery = models.JSONField(default=dict)
|
#battery = models.JSONField(default=dict)
|
||||||
#before_install = models.JSONField(default=dict, null=True) # dict or str
|
#before_install = models.JSONField(default=dict, null=True) # dict or str
|
||||||
bluetooth = models.ForeignKey(Bluetooth, on_delete=models.CASCADE, null=True)
|
bluetooth = models.ForeignKey(Bluetooth, on_delete=models.CASCADE, null=True)
|
||||||
|
|
|
@ -1,9 +1,10 @@
|
||||||
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 BluetoothViewSet, CameraViewSet, DeviceViewSet, SingleDeviceViewSet
|
from suitablephones.views import BluetoothViewSet, CameraViewSet, DeviceViewSet, SingleDeviceViewSet, SearchDeviceViewSet
|
||||||
|
|
||||||
router = routers.DefaultRouter(trailing_slash=False)
|
router = routers.DefaultRouter(trailing_slash=False)
|
||||||
|
router.register(r'search', SearchDeviceViewSet)
|
||||||
router.register(r'device', SingleDeviceViewSet)
|
router.register(r'device', SingleDeviceViewSet)
|
||||||
router.register(r'devices', DeviceViewSet)
|
router.register(r'devices', DeviceViewSet)
|
||||||
router.register(r'bluetooth', BluetoothViewSet)
|
router.register(r'bluetooth', BluetoothViewSet)
|
||||||
|
|
|
@ -7,14 +7,24 @@ from suitablephones.models import Bluetooth, Camera, Device
|
||||||
from suitablephones.serializers import (BluetoothSerializer, CameraSerializer,
|
from suitablephones.serializers import (BluetoothSerializer, CameraSerializer,
|
||||||
DeviceSerializer, DeviceSerializerShort)
|
DeviceSerializer, DeviceSerializerShort)
|
||||||
|
|
||||||
|
class SearchDeviceViewSet(viewsets.ModelViewSet):
|
||||||
|
queryset = Device.objects.all()
|
||||||
|
serializer_class = DeviceSerializer
|
||||||
|
|
||||||
|
def get_queryset(self):
|
||||||
|
query = self.request.query_params.get('q')
|
||||||
|
if query:
|
||||||
|
self.queryset = self.queryset.filter(codename__icontains=query) | self.queryset.filter(name__icontains=query) | self.queryset.filter(vendor__icontains=query)
|
||||||
|
return self.queryset
|
||||||
|
|
||||||
class SingleDeviceViewSet(viewsets.ModelViewSet):
|
class SingleDeviceViewSet(viewsets.ModelViewSet):
|
||||||
queryset = Device.objects.all()
|
queryset = Device.objects.all()
|
||||||
serializer_class = DeviceSerializer
|
serializer_class = DeviceSerializer
|
||||||
|
|
||||||
def get_queryset(self):
|
def get_queryset(self):
|
||||||
params = self.request.query_params.get('search')
|
codename = self.request.query_params.get('codename')
|
||||||
if params:
|
if codename:
|
||||||
self.queryset = self.queryset.filter(codename__icontains=params) | self.queryset.filter(name__icontains=params) | self.queryset.filter(vendor__icontains=params)
|
self.queryset = self.queryset.filter(codename__icontains=codename)
|
||||||
return self.queryset
|
return self.queryset
|
||||||
|
|
||||||
# ViewSets define the view behavior.
|
# ViewSets define the view behavior.
|
||||||
|
|
Loading…
Reference in a new issue