fix save screen

This commit is contained in:
d0c 2023-02-17 13:59:02 +01:00
parent e2c79cf698
commit 512b3dfba9
2 changed files with 17 additions and 15 deletions

View file

@ -16,11 +16,11 @@ def update_repo():
if pull_status.returncode != 0: if pull_status.returncode != 0:
logging.error("Error pulling repo") logging.error("Error pulling repo")
def set_screen(args): def set_screens(args):
#if type(args) #if type(args)
screen = Screen.objects.filter(**args) screen = Screen.objects.filter(**args)
if not screen.exists(): if not screen.exists():
screen = Screen() screen = Screens()
for subkey, subvalue in args.items(): for subkey, subvalue in args.items():
if subkey == 'size': if subkey == 'size':
size_mm = subvalue.split(' ')[0] size_mm = subvalue.split(' ')[0]
@ -119,9 +119,9 @@ class Command(BaseCommand):
if type(value) is list: if type(value) is list:
for s in value: for s in value:
for k,v in s.items(): for k,v in s.items():
screen.append(set_screen(v)) screen.append(set_screens(v))
elif type(value) is dict: elif type(value) is dict:
screen.append(set_screen(value)) screen.append(set_screens(value))
else: else:
setattr(dev, key, value) setattr(dev, key, value)
except yaml.YAMLError as exc: except yaml.YAMLError as exc:
@ -131,5 +131,7 @@ class Command(BaseCommand):
dev.bluetooth = bluetooth dev.bluetooth = bluetooth
for cam in cameras: for cam in cameras:
dev.cameras.add(cam) dev.cameras.add(cam)
for scr in screen:
dev.screen.add(scr)
dev.save() dev.save()

View file

@ -7,7 +7,7 @@ class Bluetooth(models.Model):
profiles = models.CharField(max_length=100, blank=True, null=True) profiles = models.CharField(max_length=100, blank=True, null=True)
def __str__(self): def __str__(self):
return f"{self.spec} - {self.profiles}" return f"{self.spec} - {self.profiles}"
class Camera(models.Model): class Camera(models.Model):
@ -20,18 +20,18 @@ class Camera(models.Model):
info = models.CharField(max_length=100, null=True) info = models.CharField(max_length=100, null=True)
def __str__(self): 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): class Screen(models.Model):
size = models.CharField(max_length=500, null=True) size = models.CharField(max_length=500, null=True)
size_mm = models.DecimalField(max_digits=5, decimal_places=1) size_mm = models.DecimalField(max_digits=5, decimal_places=1)
size_in = models.DecimalField(max_digits=5, decimal_places=1) size_in = models.DecimalField(max_digits=5, decimal_places=1)
resolution = models.CharField(max_length=100) resolution = models.CharField(max_length=100)
density = models.CharField(max_length=100) density = models.CharField(max_length=100)
technology = models.CharField(max_length=100) technology = models.CharField(max_length=100)
def __str__(self): def __str__(self):
return f"{self.size_in} - {self.density} - {self.technology}" return f"{self.size_in} - {self.density} - {self.technology}"
class Device(models.Model): class Device(models.Model):
#architecture = models.JSONField(default=dict) #architecture = models.JSONField(default=dict)