From 512b3dfba96c94f2fba2f1bda8d860812a9a3592 Mon Sep 17 00:00:00 2001 From: d0c Date: Fri, 17 Feb 2023 13:59:02 +0100 Subject: [PATCH] fix save screen --- .../management/commands/fetchphones.py | 10 +++++---- suitablephones/models.py | 22 +++++++++---------- 2 files changed, 17 insertions(+), 15 deletions(-) diff --git a/suitablephones/management/commands/fetchphones.py b/suitablephones/management/commands/fetchphones.py index 27fc5b9..8804dd5 100644 --- a/suitablephones/management/commands/fetchphones.py +++ b/suitablephones/management/commands/fetchphones.py @@ -16,11 +16,11 @@ def update_repo(): if pull_status.returncode != 0: logging.error("Error pulling repo") -def set_screen(args): +def set_screens(args): #if type(args) screen = Screen.objects.filter(**args) if not screen.exists(): - screen = Screen() + screen = Screens() for subkey, subvalue in args.items(): if subkey == 'size': size_mm = subvalue.split(' ')[0] @@ -119,9 +119,9 @@ class Command(BaseCommand): if type(value) is list: for s in value: for k,v in s.items(): - screen.append(set_screen(v)) + screen.append(set_screens(v)) elif type(value) is dict: - screen.append(set_screen(value)) + screen.append(set_screens(value)) else: setattr(dev, key, value) except yaml.YAMLError as exc: @@ -131,5 +131,7 @@ class Command(BaseCommand): dev.bluetooth = bluetooth for cam in cameras: dev.cameras.add(cam) + for scr in screen: + dev.screen.add(scr) dev.save() \ No newline at end of file diff --git a/suitablephones/models.py b/suitablephones/models.py index 998645b..965f844 100644 --- a/suitablephones/models.py +++ b/suitablephones/models.py @@ -7,7 +7,7 @@ class Bluetooth(models.Model): profiles = models.CharField(max_length=100, blank=True, null=True) def __str__(self): - return f"{self.spec} - {self.profiles}" + return f"{self.spec} - {self.profiles}" class Camera(models.Model): @@ -20,18 +20,18 @@ class Camera(models.Model): info = models.CharField(max_length=100, null=True) def __str__(self): - return f" {self.flash} - {str(self.megapixel)} - {self.info}" + return f" {self.flash} - {str(self.megapixel)} - {self.info}" class Screen(models.Model): - size = models.CharField(max_length=500, null=True) - size_mm = models.DecimalField(max_digits=5, decimal_places=1) - size_in = models.DecimalField(max_digits=5, decimal_places=1) - resolution = models.CharField(max_length=100) - density = models.CharField(max_length=100) - technology = models.CharField(max_length=100) - - def __str__(self): - return f"{self.size_in} - {self.density} - {self.technology}" + size = models.CharField(max_length=500, null=True) + size_mm = models.DecimalField(max_digits=5, decimal_places=1) + size_in = models.DecimalField(max_digits=5, decimal_places=1) + resolution = models.CharField(max_length=100) + density = models.CharField(max_length=100) + technology = models.CharField(max_length=100) + + def __str__(self): + return f"{self.size_in} - {self.density} - {self.technology}" class Device(models.Model): #architecture = models.JSONField(default=dict)