|
@@ -76,12 +76,16 @@ class SmartSceneView(View):
|
|
|
gateway_sub_device_qs = gateway_sub_device_qs.values('id', 'device_type', 'nickname', 'status')
|
|
|
sub_device_list = []
|
|
|
for gateway_sub_device in gateway_sub_device_qs:
|
|
|
- room_id = FamilyRoomDevice.objects.filter(sub_device=gateway_sub_device['id']).values('room_id')[0][
|
|
|
- 'room_id']
|
|
|
- try:
|
|
|
- gateway_sub_device['room_name'] = FamilyRoom.objects.get(id=room_id).name
|
|
|
- except ObjectDoesNotExist:
|
|
|
+ family_room_device_qs = FamilyRoomDevice.objects.filter(sub_device=gateway_sub_device['id']).\
|
|
|
+ values('room_id')
|
|
|
+ if not family_room_device_qs.exists():
|
|
|
gateway_sub_device['room_name'] = ''
|
|
|
+ else:
|
|
|
+ room_id = family_room_device_qs[0]['room_id']
|
|
|
+ try:
|
|
|
+ gateway_sub_device['room_name'] = FamilyRoom.objects.get(id=room_id).name
|
|
|
+ except ObjectDoesNotExist:
|
|
|
+ gateway_sub_device['room_name'] = ''
|
|
|
gateway_sub_device.pop('id')
|
|
|
sub_device_list.append(gateway_sub_device)
|
|
|
return response.json(0, sub_device_list)
|