queryset and object creation
This commit is contained in:
parent
6a2cc0c775
commit
94d42a6d18
1 changed files with 5 additions and 3 deletions
|
@ -25,16 +25,18 @@ class Command(BaseCommand):
|
||||||
data = yaml.safe_load(stream)
|
data = yaml.safe_load(stream)
|
||||||
dev = Device()
|
dev = Device()
|
||||||
for key, value in data.items():
|
for key, value in data.items():
|
||||||
print(key)
|
|
||||||
if key == "bluetooth":
|
if key == "bluetooth":
|
||||||
|
# get() returned more than one Bluetooth -- it returned 2!
|
||||||
bt = Bluetooth.objects.filter(**value)
|
bt = Bluetooth.objects.filter(**value)
|
||||||
|
# __exact? https://docs.djangoproject.com/en/4.1/ref/models/querysets/#exact
|
||||||
if not bt.exists():
|
if not bt.exists():
|
||||||
bt = Bluetooth()
|
bt = Bluetooth()
|
||||||
for subkey, subvalue in value.items():
|
for subkey, subvalue in value.items():
|
||||||
setattr(bt, subkey, subvalue)
|
setattr(bt, subkey, subvalue)
|
||||||
bt.save()
|
bt.save()
|
||||||
else:
|
else:
|
||||||
dev.bluetooth = bt.get()
|
bt = bt.get()
|
||||||
|
dev.bluetooth = bt
|
||||||
elif key == "cameras":
|
elif key == "cameras":
|
||||||
print('camera')
|
print('camera')
|
||||||
# cam = []
|
# cam = []
|
||||||
|
|
Loading…
Reference in a new issue