diff --git a/.gitignore b/.gitignore index 0797d16..1880a0c 100644 --- a/.gitignore +++ b/.gitignore @@ -63,3 +63,5 @@ target/ # Virtualenv bin/ pyvenv.cfg + +*/migrations/* diff --git a/.vscode/launch.json b/.vscode/launch.json new file mode 100644 index 0000000..b0c4647 --- /dev/null +++ b/.vscode/launch.json @@ -0,0 +1,21 @@ +{ + // Use IntelliSense to learn about possible attributes. + // Hover to view descriptions of existing attributes. + // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 + "version": "0.2.0", + "configurations": [ + + { + "name": "Python: Django", + "type": "python", + "request": "launch", + //"python": "/home/francesco/Code/suitablephones/", + "program": "${workspaceFolder}/manage.py", + "args": [ + "fetchphones" + ], + "django": true, + "justMyCode": true + } + ] +} \ No newline at end of file diff --git a/suitablephones/management/commands/fetchphones.py b/suitablephones/management/commands/fetchphones.py index 6521d47..e7db805 100644 --- a/suitablephones/management/commands/fetchphones.py +++ b/suitablephones/management/commands/fetchphones.py @@ -26,16 +26,15 @@ class Command(BaseCommand): dev = Device() for key, value in data.items(): if key == "bluetooth": - bt = Bluetooth.objects.filter(*value.items()) + bt = Bluetooth.objects.filter(**value) if not bt.exists(): bt = Bluetooth() for subkey, subvalue in value.items(): - bt - for subkey, subvalue in value.items(): - #logging.warning(type(subkey)) - #logging.warning(subkey) - #print(type(subvalue) + subvalue) - setattr(bt, subkey, subvalue) + setattr(bt, subkey, subvalue) + bt.save() + #for subkey, subvalue in value.items(): + # setattr(bt, subkey, subvalue) + # bt.save() # elif key == "cameras": # cam = [] # for c in Camera.objects.filter(*value.items()) diff --git a/suitablephones/models.py b/suitablephones/models.py index 4146567..fb85dea 100644 --- a/suitablephones/models.py +++ b/suitablephones/models.py @@ -5,10 +5,10 @@ from django.db import models class Bluetooth(models.Model): spec = models.CharField(max_length=100) - profile = models.CharField(max_length=100) + profiles = models.CharField(max_length=100) def __str__(self): - return f"Bluetooth: {self.spec}" + return f"Bluetooth: {self.spec - self.profiles}" class Camera(models.Model): @@ -30,7 +30,7 @@ class Device(models.Model): architecture = models.CharField(max_length=100) #before_install = bluetooth = models.ForeignKey(Bluetooth, on_delete=models.CASCADE) - cameras = models.ManyToManyField(Camera) + #cameras = models.ManyToManyField(Camera) cpu = models.CharField(max_length=100) codename = models.CharField(max_length=100) cpu_cores = models.CharField(max_length=100) diff --git a/suitablephones/urls.py b/suitablephones/urls.py index 283581b..bb316df 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)),