ソースを参照

queryset and object creation

d0c 1 年間 前
コミット
94d42a6d18
1 ファイル変更5 行追加3 行削除
  1. 5 3
      suitablephones/management/commands/fetchphones.py

+ 5 - 3
suitablephones/management/commands/fetchphones.py

@@ -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 = []