adjustment
This commit is contained in:
parent
1be0dfa7c4
commit
bc12a30f1c
4 changed files with 18 additions and 11 deletions
|
@ -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'
|
||||
|
|
|
@ -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()
|
||||
|
|
@ -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):
|
||||
|
|
|
@ -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)
|
||||
|
|
Loading…
Reference in a new issue