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)
|
||||
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 = []
|
||||
|
|
Loading…
Reference in a new issue