diff --git a/.gitignore b/.gitignore index a988240..df33a7d 100644 --- a/.gitignore +++ b/.gitignore @@ -1,5 +1,6 @@ todo.md db.sqlite3 +*.test.json # ---> Python # Byte-compiled / optimized / DLL files diff --git a/suitablephones/management/commands/fetchphones.py b/suitablephones/management/commands/fetchphones.py index e58059c..5288e82 100644 --- a/suitablephones/management/commands/fetchphones.py +++ b/suitablephones/management/commands/fetchphones.py @@ -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() \ No newline at end of file diff --git a/suitablephones/models.py b/suitablephones/models.py index a94358d..e8c37ef 100644 --- a/suitablephones/models.py +++ b/suitablephones/models.py @@ -64,4 +64,4 @@ class Device(models.Model): wifi = models.CharField(max_length=200, null=True) def __str__(self): - return 'Device: ' + self.name \ No newline at end of file + return 'Device: ' + self.name + ' - ' + self.codename \ No newline at end of file diff --git a/suitablephones/serializers.py b/suitablephones/serializers.py index 02decc6..6821b3e 100644 --- a/suitablephones/serializers.py +++ b/suitablephones/serializers.py @@ -12,7 +12,7 @@ class CameraSerializer(serializers.ModelSerializer): class BluetoothSerializer(serializers.ModelSerializer): class Meta: model = Bluetooth - exclude = [] + exclude = ["id"] diff --git a/suitablephones/urls.py b/suitablephones/urls.py index bb316df..283581b 100644 --- a/suitablephones/urls.py +++ b/suitablephones/urls.py @@ -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)), diff --git a/suitablephones/views.py b/suitablephones/views.py index 40eb79c..b13cb0a 100644 --- a/suitablephones/views.py +++ b/suitablephones/views.py @@ -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