first working
This commit is contained in:
parent
90d4832488
commit
2a78fa8262
6 changed files with 41 additions and 9 deletions
|
@ -24,4 +24,4 @@ virtualenv .
|
||||||
bin/pip install -r requirements.txt
|
bin/pip install -r requirements.txt
|
||||||
bin/python manage.py migrate
|
bin/python manage.py migrate
|
||||||
bin/python manage.py createsuperuser
|
bin/python manage.py createsuperuser
|
||||||
bin/python manage.py startserver
|
bin/python manage.py runserver
|
||||||
|
|
|
@ -17,7 +17,7 @@ from django.contrib import admin
|
||||||
from django.urls import include, path
|
from django.urls import include, path
|
||||||
|
|
||||||
urlpatterns = [
|
urlpatterns = [
|
||||||
path('api-auth/', include('rest_framework.urls')),
|
path('', include('suitablephones.urls')),
|
||||||
path('admin/', admin.site.urls),
|
path('admin/', admin.site.urls),
|
||||||
]
|
]
|
||||||
|
|
||||||
|
|
|
@ -7,6 +7,9 @@ class Bluetooth(models.Model):
|
||||||
spec = models.CharField(max_length=100)
|
spec = models.CharField(max_length=100)
|
||||||
profile = models.CharField(max_length=100)
|
profile = models.CharField(max_length=100)
|
||||||
|
|
||||||
|
def __str__(self):
|
||||||
|
return f"Bluetooth: {self.spec}"
|
||||||
|
|
||||||
|
|
||||||
class Camera(models.Model):
|
class Camera(models.Model):
|
||||||
class FLASHES(models.TextChoices):
|
class FLASHES(models.TextChoices):
|
||||||
|
@ -15,6 +18,9 @@ class Camera(models.Model):
|
||||||
|
|
||||||
megapixel = models.DecimalField(max_digits=5, decimal_places=1)
|
megapixel = models.DecimalField(max_digits=5, decimal_places=1)
|
||||||
flash = models.CharField(max_length=100, choices=FLASHES.choices)
|
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)
|
#Devices.object.filter(flash=Camera.FLASEHS.LED)
|
||||||
|
|
||||||
|
@ -53,5 +59,7 @@ class Device(models.Model):
|
||||||
vendor = models.CharField(max_length=100)
|
vendor = models.CharField(max_length=100)
|
||||||
vendor_short = models.CharField(max_length=100)
|
vendor_short = models.CharField(max_length=100)
|
||||||
#versions = <class 'list'>
|
#versions = <class 'list'>
|
||||||
|
wifi = models.CharField(max_length=100)
|
||||||
wifi = models.CharField(max_length=100)
|
|
||||||
|
def __str__(self):
|
||||||
|
return 'Device: ' + self.name
|
10
suitablephones/serializers.py
Normal file
10
suitablephones/serializers.py
Normal 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']
|
|
@ -1,7 +1,14 @@
|
||||||
from django.urls import path
|
from django.urls import include, path
|
||||||
from suitablephones.views import SuitablePhones
|
from rest_framework import routers
|
||||||
|
|
||||||
|
from suitablephones.views import DeviceViewSet, SuitablePhones
|
||||||
|
|
||||||
|
router = routers.DefaultRouter()
|
||||||
|
router.register(r'devices', DeviceViewSet)
|
||||||
|
|
||||||
urlpatterns = [
|
urlpatterns = [
|
||||||
|
path('api/', include(router.urls)),
|
||||||
|
path('api-auth/', include('rest_framework.urls', namespace='rest_framework')),
|
||||||
path('suitablephones/', SuitablePhones.as_view(), name='suitablephones'),
|
path('suitablephones/', SuitablePhones.as_view(), name='suitablephones'),
|
||||||
]
|
]
|
||||||
|
|
||||||
|
|
|
@ -1,7 +1,8 @@
|
||||||
from django.shortcuts import render
|
|
||||||
from django.http import HttpResponse
|
|
||||||
from django.views.generic.list import ListView
|
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):
|
class SuitablePhones(ListView):
|
||||||
|
@ -14,3 +15,9 @@ class SuitablePhones(ListView):
|
||||||
def get_queryset(self):
|
def get_queryset(self):
|
||||||
camera = self.get_request_camera()
|
camera = self.get_request_camera()
|
||||||
return self.model.objects.filter(camera=camera)
|
return self.model.objects.filter(camera=camera)
|
||||||
|
|
||||||
|
|
||||||
|
# ViewSets define the view behavior.
|
||||||
|
class DeviceViewSet(viewsets.ModelViewSet):
|
||||||
|
queryset = Device.objects.all()
|
||||||
|
serializer_class = DeviceSerializer
|
Loading…
Reference in a new issue