adjustment

This commit is contained in:
d0c 2023-01-23 17:30:13 +01:00
parent 1be0dfa7c4
commit bc12a30f1c
4 changed files with 18 additions and 11 deletions

View file

@ -139,4 +139,4 @@ REST_FRAMEWORK = {
'DEFAULT_FILTER_BACKENDS': ['django_filters.rest_framework.DjangoFilterBackend']
}
LINEAGEWIKI = '/home/d0c/Code/lineage_wiki'
LINEAGEWIKI = '/home/francesco/Code/lineage_wiki'

View file

@ -39,13 +39,17 @@ class Command(BaseCommand):
devicesdir = settings.LINEAGEWIKI + "/_data/devices/"
# import pdb; pdb.set_trace()
for filename in os.listdir(devicesdir):
dev = Device()
cameras = []
bluetooth = {}
peripherals = []
with open(os.path.join(devicesdir, filename), "r") as stream:
try:
data = yaml.safe_load(stream)
print(data['codename'])
dev = Device()
for key, value in data.items():
# if key == "architecture":
# if type(value) == dict():
# setattr(dev, key, value)
@ -66,16 +70,14 @@ class Command(BaseCommand):
if not hasattr(value, 'profiles'):
setattr(bt, 'profiles', None)
setattr(bt, subkey, subvalue)
bt.save()
bt.save()
else:
bt = bt.get(spec=value['spec'], profiles=value['profiles'])
dev.bluetooth = bt
dev.save()
bluetooth = bt
elif key == "cameras":
dev.save()
for c in value:
cam = set_camera(c)
dev.cameras.add(cam)
cameras.append(cam)
elif key == "peripherals":
if str(value) == "None":
value = None
@ -84,8 +86,12 @@ class Command(BaseCommand):
value = None
else:
setattr(dev, key, value)
dev.save()
except yaml.YAMLError as exc:
print(exc)
stream.close()
stream.close()
dev.save()
dev.bluetooth = bluetooth
for camera in cameras:
dev.cameras.add(cam)
dev.save()

View file

@ -20,7 +20,7 @@ class Camera(models.Model):
info = models.CharField(max_length=100, null=True)
def __str__(self):
return f" {self.flash - self.megapixel - self.info}"
return f" {self.flash} - {str(self.megapixel)} - {self.info}"
class Device(models.Model):

View file

@ -15,6 +15,7 @@ class BluetoothSerializer(serializers.ModelSerializer):
exclude = []
class DeviceSerializer(serializers.ModelSerializer):
bluetooth = BluetoothSerializer(many=False, read_only=True)
cameras = CameraSerializer(many=True, read_only=True)