first working

This commit is contained in:
Matteo Parrucci 2023-01-03 11:50:47 +01:00
parent 90d4832488
commit 2a78fa8262
6 changed files with 41 additions and 9 deletions

View file

@ -24,4 +24,4 @@ virtualenv .
bin/pip install -r requirements.txt
bin/python manage.py migrate
bin/python manage.py createsuperuser
bin/python manage.py startserver
bin/python manage.py runserver

View file

@ -17,7 +17,7 @@ from django.contrib import admin
from django.urls import include, path
urlpatterns = [
path('api-auth/', include('rest_framework.urls')),
path('', include('suitablephones.urls')),
path('admin/', admin.site.urls),
]

View file

@ -7,6 +7,9 @@ class Bluetooth(models.Model):
spec = models.CharField(max_length=100)
profile = models.CharField(max_length=100)
def __str__(self):
return f"Bluetooth: {self.spec}"
class Camera(models.Model):
class FLASHES(models.TextChoices):
@ -15,6 +18,9 @@ class Camera(models.Model):
megapixel = models.DecimalField(max_digits=5, decimal_places=1)
flash = models.CharField(max_length=100, choices=FLASHES.choices)
def __str__(self):
return f"Camera: {self.megapixel} - {self.flash}"
#Devices.object.filter(flash=Camera.FLASEHS.LED)
@ -53,5 +59,7 @@ class Device(models.Model):
vendor = models.CharField(max_length=100)
vendor_short = models.CharField(max_length=100)
#versions = <class 'list'>
wifi = models.CharField(max_length=100)
wifi = models.CharField(max_length=100)
def __str__(self):
return 'Device: ' + self.name

View file

@ -0,0 +1,10 @@
from rest_framework import serializers
from suitablephones.models import Device
# Serializers define the API representation.
class DeviceSerializer(serializers.HyperlinkedModelSerializer):
class Meta:
model = Device
fields = ['cpu', 'kernel', 'name']

View file

@ -1,7 +1,14 @@
from django.urls import path
from suitablephones.views import SuitablePhones
from django.urls import include, path
from rest_framework import routers
from suitablephones.views import DeviceViewSet, SuitablePhones
router = routers.DefaultRouter()
router.register(r'devices', DeviceViewSet)
urlpatterns = [
path('api/', include(router.urls)),
path('api-auth/', include('rest_framework.urls', namespace='rest_framework')),
path('suitablephones/', SuitablePhones.as_view(), name='suitablephones'),
]

View file

@ -1,7 +1,8 @@
from django.shortcuts import render
from django.http import HttpResponse
from django.views.generic.list import ListView
from suitablephones.models import Device, Camera
from rest_framework import viewsets
from suitablephones.models import Device
from suitablephones.serializers import DeviceSerializer
class SuitablePhones(ListView):
@ -14,3 +15,9 @@ class SuitablePhones(ListView):
def get_queryset(self):
camera = self.get_request_camera()
return self.model.objects.filter(camera=camera)
# ViewSets define the view behavior.
class DeviceViewSet(viewsets.ModelViewSet):
queryset = Device.objects.all()
serializer_class = DeviceSerializer