queryset and object creation

This commit is contained in:
d0c 2023-01-12 18:30:28 +01:00
parent 6a2cc0c775
commit 94d42a6d18

View file

@ -25,16 +25,18 @@ class Command(BaseCommand):
data = yaml.safe_load(stream)
dev = Device()
for key, value in data.items():
print(key)
if key == "bluetooth":
# get() returned more than one Bluetooth -- it returned 2!
bt = Bluetooth.objects.filter(**value)
# __exact? https://docs.djangoproject.com/en/4.1/ref/models/querysets/#exact
if not bt.exists():
bt = Bluetooth()
for subkey, subvalue in value.items():
setattr(bt, subkey, subvalue)
bt.save()
else:
dev.bluetooth = bt.get()
else:
bt = bt.get()
dev.bluetooth = bt
elif key == "cameras":
print('camera')
# cam = []