fix and filters
This commit is contained in:
parent
946a717ff6
commit
2ccf6c0cd3
6 changed files with 15 additions and 5 deletions
1
.gitignore
vendored
1
.gitignore
vendored
|
@ -1,5 +1,6 @@
|
|||
todo.md
|
||||
db.sqlite3
|
||||
*.test.json
|
||||
|
||||
# ---> Python
|
||||
# Byte-compiled / optimized / DLL files
|
||||
|
|
|
@ -91,7 +91,7 @@ class Command(BaseCommand):
|
|||
stream.close()
|
||||
dev.save()
|
||||
dev.bluetooth = bluetooth
|
||||
for camera in cameras:
|
||||
for cam in cameras:
|
||||
dev.cameras.add(cam)
|
||||
dev.save()
|
||||
|
|
@ -64,4 +64,4 @@ class Device(models.Model):
|
|||
wifi = models.CharField(max_length=200, null=True)
|
||||
|
||||
def __str__(self):
|
||||
return 'Device: ' + self.name
|
||||
return 'Device: ' + self.name + ' - ' + self.codename
|
|
@ -12,7 +12,7 @@ class CameraSerializer(serializers.ModelSerializer):
|
|||
class BluetoothSerializer(serializers.ModelSerializer):
|
||||
class Meta:
|
||||
model = Bluetooth
|
||||
exclude = []
|
||||
exclude = ["id"]
|
||||
|
||||
|
||||
|
||||
|
|
|
@ -6,7 +6,7 @@ from suitablephones.views import BluetoothViewSet, CameraViewSet, DeviceViewSet
|
|||
router = routers.DefaultRouter()
|
||||
router.register(r'devices', DeviceViewSet)
|
||||
router.register(r'bluetooth', BluetoothViewSet)
|
||||
#router.register(r'camera', CameraViewSet)
|
||||
router.register(r'camera', CameraViewSet)
|
||||
|
||||
urlpatterns = [
|
||||
path('api/', include(router.urls)),
|
||||
|
|
|
@ -15,9 +15,18 @@ class DeviceViewSet(viewsets.ModelViewSet):
|
|||
|
||||
#http://url/api/devices?megapixel=3
|
||||
def get_queryset(self):
|
||||
name = self.request.query_params.get('name')
|
||||
megapixel = self.request.query_params.get('megapixel')
|
||||
#maintainers = self.request.query_params.getlist('maintainers')
|
||||
version = self.request.query_params.get('version')
|
||||
if name:
|
||||
self.queryset = self.queryset.filter(name__icontains=name)
|
||||
if megapixel:
|
||||
self.queryset = self.queryset.filter(cameras__megapixel__lt=Decimal(megapixel))
|
||||
self.queryset = self.queryset.filter(cameras__megapixel__gt=Decimal(megapixel))
|
||||
if version:
|
||||
self.queryset = self.queryset.filter(versions__icontains=version)
|
||||
#if maintainers:
|
||||
self.queryset = self.queryset.filter(maintainers__len__gt=0)
|
||||
return self.queryset
|
||||
|
||||
|
||||
|
|
Loading…
Reference in a new issue